Skip to content

Commit 0b54f40

Browse files
fix: localhost output
1 parent ac3fb6d commit 0b54f40

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

lib/Server.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,21 @@ class Server {
598598
let networkUrlIPv4;
599599
let networkUrlIPv6;
600600

601-
if (this.hostname && this.hostname !== 'localhost') {
602-
let isIP;
601+
if (this.hostname) {
602+
if (this.hostname === 'localhost') {
603+
localhost = prettyPrintUrl('localhost');
604+
} else {
605+
let isIP;
603606

604-
try {
605-
isIP = ipaddr.parse(this.hostname);
606-
} catch (error) {
607-
// Ignore
608-
}
607+
try {
608+
isIP = ipaddr.parse(this.hostname);
609+
} catch (error) {
610+
// Ignore
611+
}
609612

610-
if (!isIP) {
611-
server = prettyPrintUrl(this.hostname);
613+
if (!isIP) {
614+
server = prettyPrintUrl(this.hostname);
615+
}
612616
}
613617
}
614618

@@ -629,8 +633,6 @@ class Server {
629633
networkUrlIPv6 = prettyPrintUrl(networkIPv6);
630634
}
631635
} else if (parsedIP.range() === 'loopback') {
632-
localhost = prettyPrintUrl('localhost');
633-
634636
if (parsedIP.kind() === 'ipv4') {
635637
loopbackIPv4 = prettyPrintUrl(parsedIP.toString());
636638
} else if (parsedIP.kind() === 'ipv6') {
@@ -653,8 +655,9 @@ class Server {
653655
this.logger.info(`Server: ${colors.info(useColor, server)}`);
654656
}
655657

656-
if (localhost) {
657-
const loopbacks = [colors.info(useColor, localhost)]
658+
if (localhost || loopbackIPv4 || loopbackIPv6) {
659+
const loopbacks = []
660+
.concat(localhost ? [colors.info(useColor, localhost)] : [])
658661
.concat(loopbackIPv4 ? [colors.info(useColor, loopbackIPv4)] : [])
659662
.concat(loopbackIPv6 ? [colors.info(useColor, loopbackIPv6)] : []);
660663

test/cli/__snapshots__/cli.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports[`CLI --host :: (IPv6): stderr 1`] = `
1010
1111
exports[`CLI --host ::1 (IPv6): stderr 1`] = `
1212
"<i> [webpack-dev-server] Project is running at:
13-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://[::1]:<port>/
13+
<i> [webpack-dev-server] Loopback: http://[::1]:<port>/
1414
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
1515
`;
1616
@@ -37,7 +37,7 @@ exports[`CLI --host 0:0:0:0:0:FFFF:7F00:0001 (IPv6): stderr 1`] = `
3737
3838
exports[`CLI --host 127.0.0.1 (IPv4): stderr 1`] = `
3939
"<i> [webpack-dev-server] Project is running at:
40-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
40+
<i> [webpack-dev-server] Loopback: http://127.0.0.1:<port>/
4141
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
4242
`;
4343

0 commit comments

Comments
 (0)