Skip to content

Commit 5d1eae4

Browse files
committed
feat(cli): "serve" cmd new param: "index" (defaults to /index.html)
1 parent 3da680b commit 5d1eae4

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

cli/bin/quasar-serve

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ const argv = parseArgs(process.argv.slice(2), {
1313
c: 'cache',
1414
m: 'micro',
1515
history: 'history',
16+
i: 'index',
1617
https: 'https',
1718
C: 'cert',
1819
K: 'key',
1920
P: 'proxy',
2021
h: 'help'
2122
},
22-
boolean: ['g', 'https', 'colors', 'S', 'history', 'h'],
23-
string: ['H', 'C', 'K'],
23+
boolean: ['g', 'https', 'colors', 'history', 'h'],
24+
string: ['H', 'C', 'K', 'i'],
2425
default: {
2526
p: process.env.PORT || 4000,
2627
H: process.env.HOSTNAME || '0.0.0.0',
2728
g: true,
2829
c: 24 * 60 * 60,
2930
m: 1,
31+
i: 'index.html',
3032
colors: true
3133
}
3234
})
@@ -44,26 +46,31 @@ if (argv.help) {
4446
control is yielded to /index.js and params have no effect.
4547
4648
Options
47-
--port, -p Port to use (default: 4000)
48-
--hostname, -H Address to use (default: 0.0.0.0)
49-
--gzip, -g Compress content (default: true)
50-
--silent, -s Supress log message
51-
--colors Log messages with colors (default: true)
52-
--open, -o Open browser window after starting
53-
--cache, -c <number> Cache time (max-age) in seconds;
54-
Does not apply to /service-worker.js
55-
(default: 86400 - 24 hours)
56-
--micro, -m <seconds> Use micro-cache (default: 1 second)
57-
--history Use history api fallback;
58-
All requests fallback to index.html
59-
--https Enable HTTPS
60-
--cert, -C [path] Path to SSL cert file (Optional)
61-
--key, -K [path] Path to SSL key file (Optional)
62-
--proxy <file.js> Proxy specific requests defined in file;
63-
File must export Array ({ path, rule })
64-
See example below. "rule" is defined at:
65-
https://github.com/chimurai/http-proxy-middleware
66-
--help, -h Displays this message
49+
--port, -p Port to use (default: 4000)
50+
--hostname, -H Address to use (default: 0.0.0.0)
51+
--gzip, -g Compress content (default: true)
52+
--silent, -s Supress log message
53+
--colors Log messages with colors (default: true)
54+
--open, -o Open browser window after starting
55+
--cache, -c <number> Cache time (max-age) in seconds;
56+
Does not apply to /service-worker.js
57+
(default: 86400 - 24 hours)
58+
--micro, -m <seconds> Use micro-cache (default: 1 second)
59+
60+
--history Use history api fallback;
61+
All requests fallback to /index.html,
62+
unless using "--index" parameter
63+
--index, -i <file> History mode (only!) index url path
64+
(default: index.html)
65+
66+
--https Enable HTTPS
67+
--cert, -C [path] Path to SSL cert file (Optional)
68+
--key, -K [path] Path to SSL key file (Optional)
69+
--proxy <file.js> Proxy specific requests defined in file;
70+
File must export Array ({ path, rule })
71+
See example below. "rule" is defined at:
72+
https://github.com/chimurai/http-proxy-middleware
73+
--help, -h Displays this message
6774
6875
Proxy file example
6976
module.exports = [
@@ -127,9 +134,15 @@ if (ssrDetected === false) {
127134
: false
128135

129136
function serve (path, cache) {
130-
return express.static(resolve(path), {
137+
const opts = {
131138
maxAge: cache ? parseInt(argv.cache, 10) * 1000 : 0
132-
})
139+
}
140+
141+
if (argv.history !== true) {
142+
opts.index = argv.index
143+
}
144+
145+
return express.static(resolve(path), opts)
133146
}
134147

135148
const app = express()
@@ -155,7 +168,13 @@ if (ssrDetected === false) {
155168

156169
if (argv.history) {
157170
const history = require('connect-history-api-fallback')
158-
app.use(history())
171+
app.use(
172+
history({
173+
index: argv.index.startsWith('/')
174+
? argv.index
175+
: '/' + argv.index
176+
})
177+
)
159178
}
160179

161180
app.use('/', serve('.', true))
@@ -212,6 +231,7 @@ if (ssrDetected === false) {
212231
['Cache (max-age)', argv.cache || 'disabled'],
213232
microCacheSeconds ? ['Micro-cache', microCacheSeconds + 's'] : '',
214233
argv.history ? ['History mode', 'enabled'] : '',
234+
argv.history ? ['History mode index', argv.index] : '',
215235
argv.proxy ? ['Proxy definitions', argv.proxy] : ''
216236
]
217237
.filter(msg => msg)

docs/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,9 @@
940940
babel-plugin-transform-imports "^1.0.0"
941941

942942
"@quasar/extras@^1.1.2":
943-
version "1.3.2"
944-
resolved "https://registry.yarnpkg.com/@quasar/extras/-/extras-1.3.2.tgz#d50f34fec235b79d4e570dc7f8b36209b0a9ada1"
945-
integrity sha512-EGBvl4By7Cv/WFGD4dc2FX+iLA+GX7YOnDj8AH92Df4pSMDKxP3TdvpXRnKs3V6bfHKyafc3VklVdf30hT5EoA==
943+
version "1.3.3"
944+
resolved "https://registry.yarnpkg.com/@quasar/extras/-/extras-1.3.3.tgz#4eade1e9ad4087ec05bee676d2e2cfb5c30c1810"
945+
integrity sha512-xRXoIl0ZtRjQbTt6iLsvLMMOy8nyroeh2bahDlQmF14dkIU+gKQqKH7pMyn5as9xJq+Vubyw6957rbyasa8WOQ==
946946

947947
"@quasar/fastclick@1.1.4":
948948
version "1.1.4"

0 commit comments

Comments
 (0)