mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Ensure address is private (#2297)
* Ensure address is private Resolves #2296 * adjust rule * Update WebpackDevServerUtils.js
This commit is contained in:
@@ -52,9 +52,22 @@ function prepareUrls(protocol, host, port) {
|
||||
if (isUnspecifiedHost) {
|
||||
prettyHost = 'localhost';
|
||||
try {
|
||||
// This can only return an IPv4 address
|
||||
lanUrlForConfig = address.ip();
|
||||
if (lanUrlForConfig) {
|
||||
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
|
||||
// Check if the address is a private ip
|
||||
// https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
|
||||
if (
|
||||
/^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
|
||||
lanUrlForConfig
|
||||
)
|
||||
) {
|
||||
// Address is private, format it for later use
|
||||
lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
|
||||
} else {
|
||||
// Address is not private, so we will discard it
|
||||
lanUrlForConfig = undefined;
|
||||
}
|
||||
}
|
||||
} catch (_e) {
|
||||
// ignored
|
||||
|
||||
Reference in New Issue
Block a user