Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 14 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 Expand Up @@ -284,6 +293,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;
}

Expand Down