Skip to content

Commit 52c3d69

Browse files
authored
refactor: rename host to hostname in client.webSocketURL (#3456)
1 parent d13a058 commit 52c3d69

17 files changed

+57
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Options:
108108
--client-transport <value> Allows to set custom transport to communicate with dev server.
109109
--client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not
110110
always know where to connect to).
111-
--client-web-socket-url-host <value> Tells clients connected to devServer to use the provided host.
111+
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided host.
112112
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
113113
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
114114
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.

bin/cli-flags.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,18 @@ module.exports = {
200200
simpleType: 'string',
201201
multiple: false,
202202
},
203-
'client-web-socket-url-host': {
203+
'client-web-socket-url-hostname': {
204204
configs: [
205205
{
206206
type: 'string',
207207
multiple: false,
208208
description:
209-
'Tells clients connected to devServer to use the provided host.',
210-
path: 'client.webSocketURL.host',
209+
'Tells clients connected to devServer to use the provided hostname.',
210+
path: 'client.webSocketURL.hostname',
211211
},
212212
],
213213
description:
214-
'Tells clients connected to devServer to use the provided host.',
214+
'Tells clients connected to devServer to use the provided hostname.',
215215
simpleType: 'string',
216216
multiple: false,
217217
},

lib/Server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,9 @@ class Server {
921921
}
922922
}
923923

924-
// Also allow if `client.webSocketURL.host` provided
924+
// Also allow if `client.webSocketURL.hostname` provided
925925
if (typeof this.options.client.webSocketURL !== 'undefined') {
926-
return this.options.client.webSocketURL.host === hostname;
926+
return this.options.client.webSocketURL.hostname === hostname;
927927
}
928928

929929
// disallow

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
"type": "object",
146146
"additionalProperties": false,
147147
"properties": {
148-
"host": {
149-
"description": "Tells clients connected to devServer to use the provided host.",
148+
"hostname": {
149+
"description": "Tells clients connected to devServer to use the provided hostname.",
150150
"type": "string",
151151
"minLength": 1
152152
},

lib/utils/DevServerPlugin.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,38 @@ class DevServerPlugin {
2525
/** @type {"ws:" | "wss:" | "http:" | "https:" | "auto:"} */
2626
let protocol;
2727

28-
// We are proxying dev server and need to specify custom `host`
28+
// We are proxying dev server and need to specify custom `hostname`
2929
if (typeof options.client.webSocketURL.protocol !== 'undefined') {
3030
protocol = options.client.webSocketURL.protocol;
3131
} else {
3232
protocol = options.https ? 'wss:' : 'ws:';
3333
}
3434

3535
/** @type {string} */
36-
let host;
36+
let hostname;
3737

38-
// SockJS is not supported server mode, so `host` and `port` can't specified, let's ignore them
38+
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
3939
// TODO show warning about this
4040
const isSockJSType = options.webSocketServer.type === 'sockjs';
4141

42-
// We are proxying dev server and need to specify custom `host`
43-
if (typeof options.client.webSocketURL.host !== 'undefined') {
44-
host = options.client.webSocketURL.host;
42+
// We are proxying dev server and need to specify custom `hostname`
43+
if (typeof options.client.webSocketURL.hostname !== 'undefined') {
44+
hostname = options.client.webSocketURL.hostname;
4545
}
46-
// Web socket server works on custom `host`, only for `ws` because `sock-js` is not support custom `host`
46+
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
4747
else if (
4848
typeof options.webSocketServer.options.host !== 'undefined' &&
4949
!isSockJSType
5050
) {
51-
host = options.webSocketServer.options.host;
51+
hostname = options.webSocketServer.options.host;
5252
}
5353
// The `host` option is specified
5454
else if (typeof this.options.host !== 'undefined') {
55-
host = this.options.host;
55+
hostname = this.options.host;
5656
}
5757
// The `port` option is not specified
5858
else {
59-
host = '0.0.0.0';
59+
hostname = '0.0.0.0';
6060
}
6161

6262
/** @type {number | string} */
@@ -130,7 +130,7 @@ class DevServerPlugin {
130130
new URL(
131131
`${protocol}//${username}${password ? `:${password}` : ''}${
132132
username || password ? `@` : ''
133-
}${ipaddr.IPv6.isIPv6(host) ? `[${host}]` : host}${
133+
}${ipaddr.IPv6.isIPv6(hostname) ? `[${hostname}]` : hostname}${
134134
port ? `:${port}` : ''
135135
}${path || '/'}${searchParamsString ? `?${searchParamsString}` : ''}`
136136
).toString()

lib/utils/normalizeOptions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function normalizeOptions(compiler, options, logger) {
121121

122122
options.client.webSocketURL = {
123123
protocol: parsedURL.protocol,
124-
host: parsedURL.hostname,
124+
hostname: parsedURL.hostname,
125125
port: parsedURL.port.length > 0 ? Number(parsedURL.port) : '',
126126
path: parsedURL.pathname,
127127
username: parsedURL.username,
@@ -151,7 +151,7 @@ function normalizeOptions(compiler, options, logger) {
151151

152152
if (typeof options.allowedHosts === 'undefined') {
153153
// allowedHosts allows some default hosts picked from
154-
// `options.host` or `webSocketURL.host` and `localhost`
154+
// `options.host` or `webSocketURL.hostname` and `localhost`
155155
options.allowedHosts = 'auto';
156156
}
157157
if (

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ exports[`options validate should throw an error on the "client" option with '{"u
146146
-> Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient"
147147
`;
148148

149-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"host":""}}' value 1`] = `
149+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":""}}' value 1`] = `
150150
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
151-
- options.client.webSocketURL.host should be an non-empty string.
152-
-> Tells clients connected to devServer to use the provided host."
151+
- options.client.webSocketURL.hostname should be an non-empty string.
152+
-> Tells clients connected to devServer to use the provided hostname."
153153
`;
154154

155-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"host":true,"path":"","port":8080}}' value 1`] = `
155+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"path":"","port":8080}}' value 1`] = `
156156
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
157-
- options.client.webSocketURL.host should be a non-empty string.
158-
-> Tells clients connected to devServer to use the provided host."
157+
- options.client.webSocketURL.hostname should be a non-empty string.
158+
-> Tells clients connected to devServer to use the provided hostname."
159159
`;
160160

161161
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"path":true}}' value 1`] = `
@@ -172,7 +172,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
172172
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
173173
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
174174
- options.client.webSocketURL should be one of these:
175-
non-empty string | object { host?, path?, password?, port?, protocol?, username? }
175+
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
176176
-> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
177177
Details:
178178
* options.client.webSocketURL.port should be one of these:
@@ -186,7 +186,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
186186
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
187187
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
188188
- options.client.webSocketURL should be one of these:
189-
non-empty string | object { host?, path?, password?, port?, protocol?, username? }
189+
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
190190
-> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
191191
Details:
192192
* options.client.webSocketURL.password should be a string.

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ exports[`options validate should throw an error on the "client" option with '{"u
146146
-> Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient"
147147
`;
148148

149-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"host":""}}' value 1`] = `
149+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":""}}' value 1`] = `
150150
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
151-
- options.client.webSocketURL.host should be an non-empty string.
152-
-> Tells clients connected to devServer to use the provided host."
151+
- options.client.webSocketURL.hostname should be an non-empty string.
152+
-> Tells clients connected to devServer to use the provided hostname."
153153
`;
154154

155-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"host":true,"path":"","port":8080}}' value 1`] = `
155+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"path":"","port":8080}}' value 1`] = `
156156
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
157-
- options.client.webSocketURL.host should be a non-empty string.
158-
-> Tells clients connected to devServer to use the provided host."
157+
- options.client.webSocketURL.hostname should be a non-empty string.
158+
-> Tells clients connected to devServer to use the provided hostname."
159159
`;
160160

161161
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"path":true}}' value 1`] = `
@@ -172,7 +172,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
172172
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
173173
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
174174
- options.client.webSocketURL should be one of these:
175-
non-empty string | object { host?, path?, password?, port?, protocol?, username? }
175+
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
176176
-> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
177177
Details:
178178
* options.client.webSocketURL.port should be one of these:
@@ -186,7 +186,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
186186
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
187187
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
188188
- options.client.webSocketURL should be one of these:
189-
non-empty string | object { host?, path?, password?, port?, protocol?, username? }
189+
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
190190
-> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
191191
Details:
192192
* options.client.webSocketURL.password should be a string.

test/cli/__snapshots__/basic.test.js.snap.webpack4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Options:
5757
--client-hot-entry Injects a Hot Module Replacement entry.
5858
--no-client-hot-entry Does not injects a Hot Module Replacement entry.
5959
--client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
60-
--client-web-socket-url-host <value> Tells clients connected to devServer to use the provided host.
60+
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
6161
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
6262
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
6363
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.

test/cli/__snapshots__/basic.test.js.snap.webpack5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Options:
5858
--no-client-progress Negative 'client-progress' option.
5959
--client-transport <value> Allows to set custom transport to communicate with dev server.
6060
--client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
61-
--client-web-socket-url-host <value> Tells clients connected to devServer to use the provided host.
61+
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
6262
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
6363
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
6464
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.

test/cli/client-option.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ describe('"client" CLI option', () => {
149149
expect(exitCode).toEqual(0);
150150
});
151151

152-
it('should work using "--client-web-socket-url-host"', async () => {
152+
it('should work using "--client-web-socket-url-hostname"', async () => {
153153
const { exitCode } = await testBin([
154-
'--client-web-socket-url-host',
154+
'--client-web-socket-url-hostname',
155155
'0.0.0.0',
156156
]);
157157

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ describe('web socket server URL', () => {
258258
const devServerOptions = {
259259
client: {
260260
webSocketURL: {
261-
host: devServerHost,
261+
hostname: devServerHost,
262262
},
263263
},
264264
webSocketServer,
@@ -595,7 +595,7 @@ describe('web socket server URL', () => {
595595
const devServerOptions = {
596596
client: {
597597
webSocketURL: {
598-
host: '127.0.0.1',
598+
hostname: '127.0.0.1',
599599
},
600600
},
601601
webSocketServer,
@@ -679,7 +679,7 @@ describe('web socket server URL', () => {
679679
const devServerOptions = {
680680
client: {
681681
webSocketURL: {
682-
host: '0.0.0.0',
682+
hostname: '0.0.0.0',
683683
},
684684
},
685685
webSocketServer,
@@ -1694,7 +1694,7 @@ describe('web socket server URL', () => {
16941694
client: {
16951695
webSocketURL: {
16961696
protocol: 'ws:',
1697-
host: '127.0.0.1',
1697+
hostname: '127.0.0.1',
16981698
port: port1,
16991699
path: '/ws',
17001700
},

test/server/Server.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ describe('Server', () => {
396396
const options = {
397397
client: {
398398
webSocketURL: {
399-
host: 'test.host',
399+
hostname: 'test.host',
400400
},
401401
},
402402
};

test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Object {
7878
"hotEntry": true,
7979
"overlay": true,
8080
"webSocketURL": Object {
81-
"host": "my.host",
81+
"hostname": "my.host",
8282
"port": 9000,
8383
},
8484
},
@@ -116,7 +116,7 @@ Object {
116116
"hotEntry": true,
117117
"overlay": true,
118118
"webSocketURL": Object {
119-
"host": "my.host",
119+
"hostname": "my.host",
120120
"port": 9000,
121121
},
122122
},

test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Object {
7878
"hotEntry": true,
7979
"overlay": true,
8080
"webSocketURL": Object {
81-
"host": "my.host",
81+
"hostname": "my.host",
8282
"port": 9000,
8383
},
8484
},
@@ -116,7 +116,7 @@ Object {
116116
"hotEntry": true,
117117
"overlay": true,
118118
"webSocketURL": Object {
119-
"host": "my.host",
119+
"hostname": "my.host",
120120
"port": 9000,
121121
},
122122
},

test/server/utils/normalizeOptions.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('normalizeOptions', () => {
120120
options: {
121121
client: {
122122
webSocketURL: {
123-
host: 'my.host',
123+
hostname: 'my.host',
124124
port: 9000,
125125
},
126126
},
@@ -133,7 +133,7 @@ describe('normalizeOptions', () => {
133133
options: {
134134
client: {
135135
webSocketURL: {
136-
host: 'my.host',
136+
hostname: 'my.host',
137137
port: '9000',
138138
},
139139
},

test/validate-options.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const tests = {
8181
webSocketURL: 'ws://localhost:8080',
8282
},
8383
{
84-
webSocketURL: { host: 'localhost' },
84+
webSocketURL: { hostname: 'localhost' },
8585
},
8686
{
8787
webSocketURL: { port: 8080 },
@@ -96,7 +96,7 @@ const tests = {
9696
webSocketURL: { path: '/my-path/' },
9797
},
9898
{
99-
webSocketURL: { host: 'localhost', port: 8080, path: '/my-path/' },
99+
webSocketURL: { hostname: 'localhost', port: 8080, path: '/my-path/' },
100100
},
101101
{
102102
webSocketURL: { username: 'zoro', password: 'roronoa' },
@@ -144,7 +144,7 @@ const tests = {
144144
transport: true,
145145
},
146146
{
147-
webSocketURL: { host: true, path: '', port: 8080 },
147+
webSocketURL: { hostname: true, path: '', port: 8080 },
148148
},
149149
{
150150
webSocketURL: { path: true },
@@ -153,7 +153,7 @@ const tests = {
153153
webSocketURL: { port: true },
154154
},
155155
{
156-
webSocketURL: { host: '' },
156+
webSocketURL: { hostname: '' },
157157
},
158158
{
159159
webSocketURL: { port: '' },

0 commit comments

Comments
 (0)