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

Show warning when trying to run on port below 1024 without admin permissions under Linux/macOS #2518

Merged
merged 1 commit into from
Jun 19, 2017
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
12 changes: 8 additions & 4 deletions packages/react-dev-utils/WebpackDevServerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const path = require('path');
const url = require('url');
const chalk = require('chalk');
const detect = require('detect-port-alt');
const isRoot = require('is-root');
const inquirer = require('inquirer');
const clearConsole = require('./clearConsole');
const formatWebpackMessages = require('./formatWebpackMessages');
Expand Down Expand Up @@ -378,14 +379,19 @@ function choosePort(host, defaultPort) {
if (port === defaultPort) {
return resolve(port);
}
const message = process.platform !== 'win32' &&
defaultPort < 1024 &&
!isRoot()
? `Admin permissions are required to run a server on a port below 1024.`
: `Something is already running on port ${defaultPort}.`;
if (isInteractive) {
clearConsole();
const existingProcess = getProcessForPort(defaultPort);
const question = {
type: 'confirm',
name: 'shouldChangePort',
message: chalk.yellow(
`Something is already running on port ${defaultPort}.` +
message +
`${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`
) + '\n\nWould you like to run the app on another port instead?',
default: true,
Expand All @@ -398,9 +404,7 @@ function choosePort(host, defaultPort) {
}
});
} else {
console.log(
chalk.red(`Something is already running on port ${defaultPort}.`)
);
console.log(chalk.red(message));
resolve(null);
}
}),
Expand Down
1 change: 1 addition & 0 deletions packages/react-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"gzip-size": "3.0.0",
"html-entities": "1.2.1",
"inquirer": "3.0.6",
"is-root": "1.0.0",
"opn": "5.0.0",
"recursive-readdir": "2.2.1",
"shell-quote": "1.6.1",
Expand Down