From 596ae27185e1e22651f9fc0e6b6d51b8e27f6dd5 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Mon, 12 Nov 2018 19:29:36 +0100 Subject: [PATCH 1/2] Deprecate support for `now.json` and `package.json` (#489) * Removed now.json from readme * Emit warning message if using now.json or package.json --- README.md | 2 +- bin/serve.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab867e3a..040fef2d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Now you understand how the package works! :tada: ## Configuration -To customize `serve`'s behavior, create a `serve.json` file and insert any of [these properties](https://github.com/zeit/serve-handler#options). In addition, `serve` will also detect `now.json` files if they contain the `static` property. +To customize `serve`'s behavior, create a `serve.json` file and insert any of [these properties](https://github.com/zeit/serve-handler#options). ## API diff --git a/bin/serve.js b/bin/serve.js index 5147cf0a..665389a5 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -284,6 +284,10 @@ const loadConfig = async (cwd, entry, args) => { Object.assign(config, content); console.log(info(`Discovered configuration in \`${file}\``)); + if (file === 'now.json' || file === 'package.json') { + console.error(warning('The config files `now.json` and `package.json` are deprecated. Please use `serve.json`.')); + } + break; } From f8439ae8ac6c90c2bf5efdbcee3ca2eb87538372 Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Mon, 12 Nov 2018 19:56:31 +0100 Subject: [PATCH 2/2] Brought back support for ephemeral port switching (#490) --- bin/serve.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/serve.js b/bin/serve.js index 665389a5..f04b1048 100755 --- a/bin/serve.js +++ b/bin/serve.js @@ -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; @@ -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); }); @@ -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);