Skip to content

Commit c9839d4

Browse files
committed
fix: use location.hostname as the client host by default
1 parent 8e51f68 commit c9839d4

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

lib/utils/createDomain.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ const ip = require('internal-ip');
55

66
function createDomain(options, server) {
77
const protocol = options.https ? 'https' : 'http';
8+
// use location hostname and port by default in createSocketUrl
9+
// ipv6 detection is not required as 0.0.0.0 is just used as a placeholder
810
let hostname;
911
if (options.useLocalIp) {
10-
hostname = ip.v4.sync() || 'localhost';
12+
hostname = ip.v4.sync() || '0.0.0.0';
1113
} else if (server) {
1214
hostname = server.address().address;
1315
} else {
14-
hostname = 'localhost';
16+
hostname = '0.0.0.0';
1517
}
1618
const port = server ? server.address().port : 0;
1719
// use explicitly defined public url

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ exports[`CLI --hot webpack 4 1`] = `
88
<i> Asset Size Chunks Chunk Names
99
<i> main.js X KiB main [emitted] main
1010
<i> Entrypoint main = main.js
11-
<i> [0] multi Xdir/client/default?http://localhost (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built]
12-
<i> [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built]
11+
<i> [0] multi Xdir/client/default?http://0.0.0.0 (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built]
12+
<i> [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built]
1313
<i> [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built]
1414
<i> [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built]
1515
<i> [../../../client/default/utils/createSocketUrl.js] Xdir/client/default/utils/createSocketUrl.js X KiB {main} [built]
@@ -53,9 +53,9 @@ exports[`CLI --no-hot webpack 4 1`] = `
5353
<i> Asset Size Chunks Chunk Names
5454
<i> main.js X KiB main [emitted] main
5555
<i> Entrypoint main = main.js
56-
<i> [0] multi Xdir/client/default?http://localhost ./foo.js X bytes {main} [built]
56+
<i> [0] multi Xdir/client/default?http://0.0.0.0 ./foo.js X bytes {main} [built]
5757
<i> [../../../client/clients/WebsocketClient.js] Xdir/client/clients/WebsocketClient.js X KiB {main} [built]
58-
<i> [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built]
58+
<i> [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built]
5959
<i> [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built]
6060
<i> [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built]
6161
<i> [../../../client/default/utils/createSocketUrl.js] Xdir/client/default/utils/createSocketUrl.js X KiB {main} [built]

test/server/__snapshots__/Server.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Array [
66
"client",
77
"default",
88
"index.js?http:",
9-
"localhost",
9+
"0.0.0.0",
1010
],
1111
Array [
1212
"node_modules",
@@ -26,7 +26,7 @@ Array [
2626
"client",
2727
"default",
2828
"index.js?http:",
29-
"localhost",
29+
"0.0.0.0",
3030
],
3131
Array [
3232
"node_modules",

0 commit comments

Comments
 (0)