Skip to content

Commit 4d3ee50

Browse files
fix: logic
1 parent 0b7bb65 commit 4d3ee50

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

bin/cli-flags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ module.exports = {
396396
},
397397
{
398398
name: 'allowed-hosts',
399-
type: [Boolean, String],
399+
type: String,
400400
configs: [
401401
{
402402
type: 'string',

lib/Server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ class Server {
900900
checkHeaders(headers, headerToCheck) {
901901
// allow user to opt out of this security check, at their own risk
902902
// by explicitly enabling allowedHosts
903-
if (this.options.allowedHosts.includes('auto')) {
903+
if (this.options.allowedHosts === 'all') {
904904
return true;
905905
}
906906

lib/options.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,19 @@
343343
"enum": ["auto", "all"]
344344
},
345345
{
346-
"type": "string"
346+
"type": "string",
347+
"minLength": 1
347348
},
348349
{
349350
"type": "array",
350351
"items": {
351-
"type": "string"
352+
"type": "string",
353+
"minLength": 1
352354
},
353355
"minItems": 1
354356
}
355357
],
356-
"description": "Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts"
358+
"description": "Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts"
357359
},
358360
"headers": {
359361
"anyOf": [

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
44
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
55
- configuration.allowedHosts should be one of these:
6-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
7-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
6+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
7+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
88
Details:
99
* configuration.allowedHosts should be one of these:
1010
\\"auto\\" | \\"all\\"
11-
* configuration.allowedHosts should be a string.
11+
* configuration.allowedHosts should be a non-empty string.
1212
* configuration.allowedHosts should be an array:
13-
[string, ...] (should not have fewer than 1 item)"
13+
[non-empty string, ...] (should not have fewer than 1 item)"
1414
`;
1515

1616
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
1717
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
1818
- configuration.allowedHosts should be one of these:
19-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
20-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
19+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
20+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
2121
Details:
2222
* configuration.allowedHosts should be one of these:
2323
\\"auto\\" | \\"all\\"
24-
* configuration.allowedHosts should be a string.
24+
* configuration.allowedHosts should be a non-empty string.
2525
* configuration.allowedHosts should be an array:
26-
[string, ...] (should not have fewer than 1 item)"
26+
[non-empty string, ...] (should not have fewer than 1 item)"
2727
`;
2828

2929
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
3030
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
3131
- configuration.allowedHosts should be one of these:
32-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
33-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
32+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
33+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
3434
Details:
3535
* configuration.allowedHosts should be one of these:
3636
\\"auto\\" | \\"all\\"
37-
* configuration.allowedHosts should be a string.
37+
* configuration.allowedHosts should be a non-empty string.
3838
* configuration.allowedHosts should be an array:
39-
[string, ...] (should not have fewer than 1 item)"
39+
[non-empty string, ...] (should not have fewer than 1 item)"
4040
`;
4141

4242
exports[`options validate should throw an error on the "bonjour" option with '' value 1`] = `

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = `
44
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
55
- configuration.allowedHosts should be one of these:
6-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
7-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
6+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
7+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
88
Details:
99
* configuration.allowedHosts should be one of these:
1010
\\"auto\\" | \\"all\\"
11-
* configuration.allowedHosts should be a string.
11+
* configuration.allowedHosts should be a non-empty string.
1212
* configuration.allowedHosts should be an array:
13-
[string, ...] (should not have fewer than 1 item)"
13+
[non-empty string, ...] (should not have fewer than 1 item)"
1414
`;
1515

1616
exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = `
1717
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
1818
- configuration.allowedHosts should be one of these:
19-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
20-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
19+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
20+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
2121
Details:
2222
* configuration.allowedHosts should be one of these:
2323
\\"auto\\" | \\"all\\"
24-
* configuration.allowedHosts should be a string.
24+
* configuration.allowedHosts should be a non-empty string.
2525
* configuration.allowedHosts should be an array:
26-
[string, ...] (should not have fewer than 1 item)"
26+
[non-empty string, ...] (should not have fewer than 1 item)"
2727
`;
2828

2929
exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = `
3030
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
3131
- configuration.allowedHosts should be one of these:
32-
\\"auto\\" | \\"all\\" | string | [string, ...] (should not have fewer than 1 item)
33-
-> Defines routes which are enabled by default, on by default and allows localhost. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
32+
\\"auto\\" | \\"all\\" | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
33+
-> Defines routes which are enabled by default, on by default and allows localhost/value from the 'host' option/value from the 'client.webSocketURL' option. https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
3434
Details:
3535
* configuration.allowedHosts should be one of these:
3636
\\"auto\\" | \\"all\\"
37-
* configuration.allowedHosts should be a string.
37+
* configuration.allowedHosts should be a non-empty string.
3838
* configuration.allowedHosts should be an array:
39-
[string, ...] (should not have fewer than 1 item)"
39+
[non-empty string, ...] (should not have fewer than 1 item)"
4040
`;
4141

4242
exports[`options validate should throw an error on the "bonjour" option with '' value 1`] = `

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Options:
271271
Page Applications.
272272
--compress Enable gzip compression.
273273
--no-compress Disable gzip compression.
274-
--allowed-hosts [value...] Set hosts that are allowed to access the dev
274+
--allowed-hosts <value...> Set hosts that are allowed to access the dev
275275
server.
276276
--watch-files <value...> Watch static files for file changes.
277277

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ exports[`CLI --bonjour 1`] = `
1010
`;
1111

1212
exports[`CLI --bonjour and --https 1`] = `
13-
"<i> [webpack-dev-server] Project is running at:
13+
"<i> [webpack-dev-server] Generating SSL Certificate
14+
<i> [webpack-dev-server] Project is running at:
1415
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
1516
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
1617
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
@@ -272,7 +273,7 @@ Options:
272273
Page Applications.
273274
--compress Enable gzip compression.
274275
--no-compress Disable gzip compression.
275-
--allowed-hosts [value...] Set hosts that are allowed to access the dev
276+
--allowed-hosts <value...> Set hosts that are allowed to access the dev
276277
server.
277278
--watch-files <value...> Watch static files for file changes.
278279

test/validate-options.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const tests = {
163163
failure: [''],
164164
},
165165
allowedHosts: {
166-
success: ['auto', 'all', [''], ''],
166+
success: ['auto', 'all', ['foo'], 'bar'],
167167
failure: [true, false, 123],
168168
},
169169
headers: {

0 commit comments

Comments
 (0)