Skip to content

Commit f0ee87a

Browse files
committed
feat(cli): "serve" cmd new parameter: "cors"
1 parent 5d1eae4 commit f0ee87a

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

cli/bin/quasar-serve

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const argv = parseArgs(process.argv.slice(2), {
1111
colors: 'colors',
1212
o: 'open',
1313
c: 'cache',
14+
cors: 'cors',
1415
m: 'micro',
1516
history: 'history',
1617
i: 'index',
@@ -20,7 +21,7 @@ const argv = parseArgs(process.argv.slice(2), {
2021
P: 'proxy',
2122
h: 'help'
2223
},
23-
boolean: ['g', 'https', 'colors', 'history', 'h'],
24+
boolean: ['g', 'https', 'colors', 'history', 'h', 'cors'],
2425
string: ['H', 'C', 'K', 'i'],
2526
default: {
2627
p: process.env.PORT || 4000,
@@ -70,6 +71,7 @@ if (argv.help) {
7071
File must export Array ({ path, rule })
7172
See example below. "rule" is defined at:
7273
https://github.com/chimurai/http-proxy-middleware
74+
--cors Enable CORS for all requests
7375
--help, -h Displays this message
7476
7577
Proxy file example
@@ -147,6 +149,11 @@ if (ssrDetected === false) {
147149

148150
const app = express()
149151

152+
if (argv.cors) {
153+
const cors = require('cors')
154+
app.use(cors())
155+
}
156+
150157
if (!argv.silent) {
151158
app.get('*', (req, _, next) => {
152159
console.log(
@@ -231,7 +238,8 @@ if (ssrDetected === false) {
231238
['Cache (max-age)', argv.cache || 'disabled'],
232239
microCacheSeconds ? ['Micro-cache', microCacheSeconds + 's'] : '',
233240
argv.history ? ['History mode', 'enabled'] : '',
234-
argv.history ? ['History mode index', argv.index] : '',
241+
['Index file', argv.index],
242+
argv.cors ? ['CORS', 'enabled'] : '',
235243
argv.proxy ? ['Proxy definitions', argv.proxy] : ''
236244
]
237245
.filter(msg => msg)

cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"compression": "1.7.4",
4646
"connect-history-api-fallback": "1.6.0",
4747
"consolidate": "0.15.1",
48+
"cors": "^2.8.5",
4849
"cross-spawn": "7.0.1",
4950
"download-git-repo": "1.1.0",
5051
"express": "4.17.1",

cli/yarn.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ core-util-is@~1.0.0:
391391
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
392392
integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=
393393

394+
cors@^2.8.5:
395+
version "2.8.5"
396+
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
397+
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
398+
dependencies:
399+
object-assign "^4"
400+
vary "^1"
401+
394402
create-error-class@^3.0.0:
395403
version "3.0.2"
396404
resolved "https://registry.yarnpkg.com/create-error-class/-/create-error-class-3.0.2.tgz#06be7abef947a3f14a30fd610671d401bca8b7b6"
@@ -1269,7 +1277,7 @@ npm-conf@^1.1.0:
12691277
config-chain "^1.1.11"
12701278
pify "^3.0.0"
12711279

1272-
object-assign@^4.0.1:
1280+
object-assign@^4, object-assign@^4.0.1:
12731281
version "4.1.1"
12741282
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
12751283
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
@@ -1845,7 +1853,7 @@ validate-npm-package-name@3.0.0:
18451853
dependencies:
18461854
builtins "^1.0.3"
18471855

1848-
vary@~1.1.2:
1856+
vary@^1, vary@~1.1.2:
18491857
version "1.1.2"
18501858
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
18511859
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=

0 commit comments

Comments
 (0)