Skip to content

Commit

Permalink
Show warning when trying to run on port below 1024 without admin perm…
Browse files Browse the repository at this point in the history
…issions under Linux (#2518)
  • Loading branch information
levrik authored and trueadm committed Jun 19, 2017
1 parent 2ab7ead commit b1c0faa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit b1c0faa

Please sign in to comment.