Skip to content

Commit

Permalink
Re-added --single and made --listen support ports (#384)
Browse files Browse the repository at this point in the history
* Added `--single` for SPA rewrite preset

* Allow `--listen` to accept ports directly

* Be more clear in usage
  • Loading branch information
leo authored May 29, 2018
1 parent 5d8a9d2 commit 4f135ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
25 changes: 24 additions & 1 deletion bin/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ const getHelp = () => chalk`
-d, --debug Show debugging information
-s, --single Rewrite all not-found requests to \`index.html\`
{bold ENDPOINTS}
Listen endpoints (specified by the {bold --listen} or {bold -l} options above) instruct {cyan serve}
to listen on one or more interfaces/ports, UNIX domain sockets, or Windows named pipes.
For TCP ports on hostname "localhost":
{bold $} {cyan serve} -l {underline 1234}
For TCP (traditional host/port) endpoints:
{bold $} {cyan serve} -l tcp://{underline hostname}:{underline 1234}
Expand All @@ -89,6 +95,10 @@ const getHelp = () => chalk`
`;

const parseEndpoint = str => {
if (!isNaN(str)) {
return [str];
}

const url = new URL(str);

switch (url.protocol) {
Expand Down Expand Up @@ -237,11 +247,13 @@ const loadConfig = async (cwd, entry) => {
'--help': Boolean,
'--version': Boolean,
'--listen': [parseEndpoint],
'--single': Boolean,
'--debug': Boolean,
'-h': '--help',
'-v': '--version',
'-l': '--listen',
'-d': '--debug'
'-d': '--debug',
'-s': '--single'
});
} catch (err) {
console.error(error(err.message));
Expand Down Expand Up @@ -275,6 +287,17 @@ const loadConfig = async (cwd, entry) => {

const config = await loadConfig(cwd, entry);

if (args['--single']) {
const {rewrites} = config;
const existingRewrites = Array.isArray(rewrites) ? rewrites : [];

// As the first rewrite rule, make `--single` work
config.rewrites = [{
source: '**',
destination: '/index.html'
}, ...existingRewrites];
}

for (const endpoint of args['--listen']) {
startEndpoint(endpoint, config);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ajv": "6.5.0",
"arg": "2.0.0",
"chalk": "2.4.1",
"serve-handler": "2.3.11",
"serve-handler": "2.3.12",
"update-check": "1.5.2"
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ semver@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"

[email protected].11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-2.3.11.tgz#e04b5950b7f7874adc47474ac75347dc79ceb097"
[email protected].12:
version "2.3.12"
resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-2.3.12.tgz#7c4f402753c74a7ff33b8607130b28bc45a07222"
dependencies:
bytes "3.0.0"
fast-url-parser "1.1.3"
Expand Down

0 comments on commit 4f135ea

Please sign in to comment.