Skip to content

Commit

Permalink
fix: use location.hostname as the client host by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ylemkimon committed Nov 27, 2020
1 parent 8e51f68 commit c9839d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/utils/createDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ const ip = require('internal-ip');

function createDomain(options, server) {
const protocol = options.https ? 'https' : 'http';
// use location hostname and port by default in createSocketUrl
// ipv6 detection is not required as 0.0.0.0 is just used as a placeholder
let hostname;
if (options.useLocalIp) {
hostname = ip.v4.sync() || 'localhost';
hostname = ip.v4.sync() || '0.0.0.0';
} else if (server) {
hostname = server.address().address;
} else {
hostname = 'localhost';
hostname = '0.0.0.0';
}
const port = server ? server.address().port : 0;
// use explicitly defined public url
Expand Down
8 changes: 4 additions & 4 deletions test/cli/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ exports[`CLI --hot webpack 4 1`] = `
<i> Asset Size Chunks Chunk Names
<i> main.js X KiB main [emitted] main
<i> Entrypoint main = main.js
<i> [0] multi Xdir/client/default?http://localhost (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built]
<i> [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built]
<i> [0] multi Xdir/client/default?http://0.0.0.0 (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built]
<i> [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built]
<i> [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built]
<i> [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built]
<i> [../../../client/default/utils/createSocketUrl.js] Xdir/client/default/utils/createSocketUrl.js X KiB {main} [built]
Expand Down Expand Up @@ -53,9 +53,9 @@ exports[`CLI --no-hot webpack 4 1`] = `
<i> Asset Size Chunks Chunk Names
<i> main.js X KiB main [emitted] main
<i> Entrypoint main = main.js
<i> [0] multi Xdir/client/default?http://localhost ./foo.js X bytes {main} [built]
<i> [0] multi Xdir/client/default?http://0.0.0.0 ./foo.js X bytes {main} [built]
<i> [../../../client/clients/WebsocketClient.js] Xdir/client/clients/WebsocketClient.js X KiB {main} [built]
<i> [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built]
<i> [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built]
<i> [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built]
<i> [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built]
<i> [../../../client/default/utils/createSocketUrl.js] Xdir/client/default/utils/createSocketUrl.js X KiB {main} [built]
Expand Down
4 changes: 2 additions & 2 deletions test/server/__snapshots__/Server.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Array [
"client",
"default",
"index.js?http:",
"localhost",
"0.0.0.0",
],
Array [
"node_modules",
Expand All @@ -26,7 +26,7 @@ Array [
"client",
"default",
"index.js?http:",
"localhost",
"0.0.0.0",
],
Array [
"node_modules",
Expand Down

0 comments on commit c9839d4

Please sign in to comment.