From c9839d4b408a8a11e0fdaf02a06d2451b23a984a Mon Sep 17 00:00:00 2001 From: Young Min Kin Date: Fri, 27 Nov 2020 21:36:05 +0900 Subject: [PATCH] fix: use location.hostname as the client host by default --- lib/utils/createDomain.js | 6 ++++-- test/cli/__snapshots__/cli.test.js.snap | 8 ++++---- test/server/__snapshots__/Server.test.js.snap | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/utils/createDomain.js b/lib/utils/createDomain.js index 2e3cb0f4b1..7248e7ad4e 100644 --- a/lib/utils/createDomain.js +++ b/lib/utils/createDomain.js @@ -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 diff --git a/test/cli/__snapshots__/cli.test.js.snap b/test/cli/__snapshots__/cli.test.js.snap index 2807d86871..c73d2cb1ae 100644 --- a/test/cli/__snapshots__/cli.test.js.snap +++ b/test/cli/__snapshots__/cli.test.js.snap @@ -8,8 +8,8 @@ exports[`CLI --hot webpack 4 1`] = ` Asset Size Chunks Chunk Names main.js X KiB main [emitted] main Entrypoint main = main.js - [0] multi Xdir/client/default?http://localhost (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built] - [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built] + [0] multi Xdir/client/default?http://0.0.0.0 (webpack)/hot/dev-server.js ./foo.js X bytes {main} [built] + [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built] [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built] [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built] [../../../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`] = ` Asset Size Chunks Chunk Names main.js X KiB main [emitted] main Entrypoint main = main.js - [0] multi Xdir/client/default?http://localhost ./foo.js X bytes {main} [built] + [0] multi Xdir/client/default?http://0.0.0.0 ./foo.js X bytes {main} [built] [../../../client/clients/WebsocketClient.js] Xdir/client/clients/WebsocketClient.js X KiB {main} [built] - [../../../client/default/index.js?http://localhost] Xdir/client/default?http://localhost X KiB {main} [built] + [../../../client/default/index.js?http://0.0.0.0] Xdir/client/default?http://0.0.0.0 X KiB {main} [built] [../../../client/default/overlay.js] Xdir/client/default/overlay.js X KiB {main} [built] [../../../client/default/socket.js] Xdir/client/default/socket.js X KiB {main} [built] [../../../client/default/utils/createSocketUrl.js] Xdir/client/default/utils/createSocketUrl.js X KiB {main} [built] diff --git a/test/server/__snapshots__/Server.test.js.snap b/test/server/__snapshots__/Server.test.js.snap index eb0628a2c5..e0793a9f8f 100644 --- a/test/server/__snapshots__/Server.test.js.snap +++ b/test/server/__snapshots__/Server.test.js.snap @@ -6,7 +6,7 @@ Array [ "client", "default", "index.js?http:", - "localhost", + "0.0.0.0", ], Array [ "node_modules", @@ -26,7 +26,7 @@ Array [ "client", "default", "index.js?http:", - "localhost", + "0.0.0.0", ], Array [ "node_modules",