Skip to content

Commit 7ab5ae3

Browse files
committed
refactor: code
1 parent 543f1e3 commit 7ab5ae3

File tree

7 files changed

+22
-73
lines changed

7 files changed

+22
-73
lines changed

lib/Server.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Server {
8181
}
8282
}
8383

84-
static async asyncInternalIp(family) {
84+
static async internalIP(family) {
8585
try {
8686
const { gateway } = await defaultGateway[family]();
8787
return Server.findIp(gateway);
@@ -90,7 +90,7 @@ class Server {
9090
}
9191
}
9292

93-
static syncInternalIp(family) {
93+
static internalIPSync(family) {
9494
try {
9595
const { gateway } = defaultGateway[family].sync();
9696
return Server.findIp(gateway);
@@ -102,14 +102,14 @@ class Server {
102102
static async getHostname(hostname) {
103103
if (hostname === "local-ip") {
104104
return (
105-
(await Server.asyncInternalIp("v4")) ||
106-
(await Server.asyncInternalIp("v6")) ||
105+
(await Server.internalIP("v4")) ||
106+
(await Server.internalIP("v6")) ||
107107
"0.0.0.0"
108108
);
109109
} else if (hostname === "local-ipv4") {
110-
return (await Server.asyncInternalIp("v4")) || "0.0.0.0";
110+
return (await Server.internalIP("v4")) || "0.0.0.0";
111111
} else if (hostname === "local-ipv6") {
112-
return (await Server.asyncInternalIp("v6")) || "::";
112+
return (await Server.internalIP("v6")) || "::";
113113
}
114114

115115
return hostname;
@@ -1853,13 +1853,13 @@ class Server {
18531853
if (parsedIP.range() === "unspecified") {
18541854
localhost = prettyPrintURL("localhost");
18551855

1856-
const networkIPv4 = Server.syncInternalIp("v4");
1856+
const networkIPv4 = Server.internalIPSync("v4");
18571857

18581858
if (networkIPv4) {
18591859
networkUrlIPv4 = prettyPrintURL(networkIPv4);
18601860
}
18611861

1862-
const networkIPv6 = Server.syncInternalIp("v6");
1862+
const networkIPv6 = Server.internalIPSync("v6");
18631863

18641864
if (networkIPv6) {
18651865
networkUrlIPv6 = prettyPrintURL(networkIPv6);

test/cli/host-option.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
22

3-
const { syncInternalIp } = require("../helpers/internal-ip");
43
const { testBin, normalizeStderr } = require("../helpers/test-bin");
54
const port = require("../ports-map")["cli-host"];
5+
const Server = require("../../lib/Server");
66

7-
const localIPv4 = syncInternalIp("v4");
8-
const localIPv6 = syncInternalIp("v6");
7+
const localIPv4 = Server.internalIPSync("v4");
8+
const localIPv6 = Server.internalIPSync("v6");
99

1010
describe('"host" CLI option', () => {
1111
it('should work using "--host 0.0.0.0" (IPv4)', async () => {

test/e2e/allowed-hosts.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const express = require("express");
44
const webpack = require("webpack");
55
const { createProxyMiddleware } = require("http-proxy-middleware");
6-
const { syncInternalIp } = require("../helpers/internal-ip");
76
const Server = require("../../lib/Server");
87
const config = require("../fixtures/client-config/webpack.config");
98
const runBrowser = require("../helpers/run-browser");
@@ -1132,7 +1131,7 @@ describe("allowed hosts", () => {
11321131
});
11331132

11341133
it("should always allow value from the `host` options if options.allowedHosts is auto", async () => {
1135-
const networkIP = syncInternalIp("v4");
1134+
const networkIP = Server.internalIPSync("v4");
11361135
const options = {
11371136
host: networkIP,
11381137
allowedHosts: "auto",

test/e2e/host.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use strict";
22

33
const webpack = require("webpack");
4-
const { syncInternalIp } = require("../helpers/internal-ip");
54
const Server = require("../../lib/Server");
65
const config = require("../fixtures/client-config/webpack.config");
76
const runBrowser = require("../helpers/run-browser");
87
const port = require("../ports-map").host;
98

10-
const ipv4 = syncInternalIp("v4");
11-
const ipv6 = syncInternalIp("v6");
9+
const ipv4 = Server.internalIPSync("v4");
10+
const ipv6 = Server.internalIPSync("v6");
1211
// macos requires root for using ip v6
1312
const isMacOS = process.platform === "darwin";
1413

test/e2e/web-socket-server-url.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const express = require("express");
44
const webpack = require("webpack");
55
const { createProxyMiddleware } = require("http-proxy-middleware");
6-
const { syncInternalIp } = require("../helpers/internal-ip");
76
const Server = require("../../lib/Server");
87
const config = require("../fixtures/client-config/webpack.config");
98
const runBrowser = require("../helpers/run-browser");
@@ -104,7 +103,7 @@ describe("web socket server URL", () => {
104103
it(`should work behind proxy, when hostnames are different and ports are same ("${webSocketServer}")`, async () => {
105104
const devServerHost = "127.0.0.1";
106105
const devServerPort = port1;
107-
const proxyHost = syncInternalIp("v4");
106+
const proxyHost = Server.internalIPSync("v4");
108107
const proxyPort = port1;
109108

110109
const compiler = webpack(config);
@@ -190,7 +189,7 @@ describe("web socket server URL", () => {
190189
it(`should work behind proxy, when hostnames are different and ports are different ("${webSocketServer}")`, async () => {
191190
const devServerHost = "127.0.0.1";
192191
const devServerPort = port1;
193-
const proxyHost = syncInternalIp("v4");
192+
const proxyHost = Server.internalIPSync("v4");
194193
const proxyPort = port2;
195194

196195
const compiler = webpack(config);
@@ -282,7 +281,7 @@ describe("web socket server URL", () => {
282281
it(`should work behind proxy, when the "host" option is "local-ip" and the "port" option is "auto" ("${webSocketServer}")`, async () => {
283282
process.env.WEBPACK_DEV_SERVER_BASE_PORT = 40000;
284283

285-
const proxyHost = syncInternalIp("v4");
284+
const proxyHost = Server.internalIPSync("v4");
286285
const proxyPort = port2;
287286

288287
const compiler = webpack(config);
@@ -1763,7 +1762,7 @@ describe("web socket server URL", () => {
17631762
});
17641763

17651764
it(`should work when "host" option is IPv4 ("${webSocketServer}")`, async () => {
1766-
const hostname = syncInternalIp("v4");
1765+
const hostname = Server.internalIPSync("v4");
17671766
const compiler = webpack(config);
17681767
const devServerOptions = {
17691768
webSocketServer,
@@ -1822,7 +1821,7 @@ describe("web socket server URL", () => {
18221821
});
18231822

18241823
it(`should work when "host" option is "local-ip" ("${webSocketServer}")`, async () => {
1825-
const hostname = syncInternalIp("v4");
1824+
const hostname = Server.internalIPSync("v4");
18261825
const compiler = webpack(config);
18271826
const devServerOptions = {
18281827
webSocketServer,
@@ -1881,7 +1880,7 @@ describe("web socket server URL", () => {
18811880
});
18821881

18831882
it(`should work when "host" option is "local-ipv4" ("${webSocketServer}")`, async () => {
1884-
const hostname = syncInternalIp("v4");
1883+
const hostname = Server.internalIPSync("v4");
18851884
const compiler = webpack(config);
18861885
const devServerOptions = {
18871886
webSocketServer,

test/helpers/internal-ip.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

test/server/open-option.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const webpack = require("webpack");
44
const open = require("open");
5-
const { syncInternalIp } = require("../helpers/internal-ip");
65
const Server = require("../../lib/Server");
76
const config = require("../fixtures/simple-config/webpack.config");
87
const port = require("../ports-map")["open-option"];
@@ -15,8 +14,8 @@ open.mockImplementation(() => {
1514
};
1615
});
1716

18-
const internalIPv4 = syncInternalIp("v4");
19-
// const internalIPv6 = syncInternalIp('v6');
17+
const internalIPv4 = Server.internalIPSync("v4");
18+
// const internalIPv6 = Server.internalIPSync('v6');
2019

2120
describe('"open" option', () => {
2221
let compiler;

0 commit comments

Comments
 (0)