Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-added --single and made --listen support ports #384

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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"

serve-handler@2.3.11:
version "2.3.11"
resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-2.3.11.tgz#e04b5950b7f7874adc47474ac75347dc79ceb097"
serve-handler@2.3.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