Skip to content

Commit 3c8eb97

Browse files
committed
fix: migrate wsUrl host option to hostname
1 parent 307f2e7 commit 3c8eb97

12 files changed

+48
-48
lines changed

lib/Server.js

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

923-
// Also allow if `client.webSocketURL.host` provided
923+
// Also allow if `client.webSocketURL.hostname` provided
924924
if (typeof this.options.client.webSocketURL !== 'undefined') {
925-
return this.options.client.webSocketURL.host === hostname;
925+
return this.options.client.webSocketURL.hostname === hostname;
926926
}
927927

928928
// 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: 13 additions & 13 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} */
@@ -112,9 +112,9 @@ class DevServerPlugin {
112112

113113
return encodeURIComponent(
114114
new URL(
115-
`${protocol}//${ipaddr.IPv6.isIPv6(host) ? `[${host}]` : host}${
116-
port ? `:${port}` : ''
117-
}${path || '/'}${
115+
`${protocol}//${
116+
ipaddr.IPv6.isIPv6(hostname) ? `[${hostname}]` : hostname
117+
}${port ? `:${port}` : ''}${path || '/'}${
118118
Object.keys(searchParams).length > 0
119119
? `?${Object.entries(searchParams)
120120
.map(([key, value]) => `${key}=${value}`)

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
};
@@ -149,7 +149,7 @@ function normalizeOptions(compiler, options, logger) {
149149

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

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

Lines changed: 7 additions & 7 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?, port?, protocol? }
175+
non-empty string | object { hostname?, path?, port?, protocol? }
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:

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

Lines changed: 7 additions & 7 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?, port?, protocol? }
175+
non-empty string | object { hostname?, path?, port?, protocol? }
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:

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,
@@ -1438,7 +1438,7 @@ describe('web socket server URL', () => {
14381438
client: {
14391439
webSocketURL: {
14401440
protocol: 'ws:',
1441-
host: '127.0.0.1',
1441+
hostname: '127.0.0.1',
14421442
port: port2,
14431443
path: '/ws',
14441444
},

test/server/Server.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ describe('Server', () => {
398398
const options = {
399399
client: {
400400
webSocketURL: {
401-
host: 'test.host',
401+
hostname: 'test.host',
402402
},
403403
},
404404
};

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
failure: [
@@ -141,7 +141,7 @@ const tests = {
141141
transport: true,
142142
},
143143
{
144-
webSocketURL: { host: true, path: '', port: 8080 },
144+
webSocketURL: { hostname: true, path: '', port: 8080 },
145145
},
146146
{
147147
webSocketURL: { path: true },
@@ -150,7 +150,7 @@ const tests = {
150150
webSocketURL: { port: true },
151151
},
152152
{
153-
webSocketURL: { host: '' },
153+
webSocketURL: { hostname: '' },
154154
},
155155
{
156156
webSocketURL: { port: '' },

0 commit comments

Comments
 (0)