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

Brought back support for ephemeral port switching #490

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Changes from all 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
11 changes: 10 additions & 1 deletion bin/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const registerShutdown = (fn) => {
process.on('exit', wrapper);
};

const startEndpoint = (endpoint, config, args) => {
const startEndpoint = (endpoint, config, args, previous) => {
const {isTTY} = process.stdout;
const clipboard = args['--no-clipboard'] !== true;
const compress = args['--no-compression'] !== true;
Expand All @@ -168,6 +168,11 @@ const startEndpoint = (endpoint, config, args) => {
});

server.on('error', (err) => {
if (err.code === 'EADDRINUSE' && endpoint.length === 1 && !isNaN(endpoint[0])) {
startEndpoint([0], config, args, endpoint[0]);
return;
}

console.error(error(`Failed to serve: ${err.stack}`));
process.exit(1);
});
Expand Down Expand Up @@ -207,6 +212,10 @@ const startEndpoint = (endpoint, config, args) => {
message += `\n${chalk.bold('- On Your Network:')} ${networkAddress}`;
}

if (previous) {
message += chalk.red(`\n\nThis port was picked because ${chalk.underline(previous)} is in use.`);
}

if (clipboard) {
try {
await copy(localAddress);
Expand Down