Skip to content

Commit c2ebba2

Browse files
fix: host can't be null or empty string
1 parent 7169c01 commit c2ebba2

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

lib/options.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,8 @@
375375
"description": "When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback"
376376
},
377377
"host": {
378-
"anyOf": [
379-
{
380-
"type": "string"
381-
},
382-
{
383-
"type": "null"
384-
}
385-
],
378+
"type": "string",
379+
"minLength": 1,
386380
"description": "Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
387381
},
388382
"hot": {

lib/utils/DevServerPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DevServerPlugin {
5050
host = options.webSocketServer.options.host;
5151
}
5252
// The `host` option is specified
53-
else if (typeof this.options.host !== 'undefined' && this.options.host) {
53+
else if (typeof this.options.host !== 'undefined') {
5454
host = this.options.host;
5555
}
5656
// The `port` option is not specified

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,22 @@ exports[`options validate should throw an error on the "historyApiFallback" opti
190190
object { … }"
191191
`;
192192

193+
exports[`options validate should throw an error on the "host" option with '' value 1`] = `
194+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
195+
- configuration.host should be an non-empty string.
196+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
197+
`;
198+
193199
exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
194200
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
195-
- configuration.host should be one of these:
196-
string | null
197-
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost
198-
Details:
199-
* configuration.host should be a string.
200-
* configuration.host should be a null."
201+
- configuration.host should be a non-empty string.
202+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
203+
`;
204+
205+
exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
206+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
207+
- configuration.host should be a non-empty string.
208+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
201209
`;
202210

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

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,22 @@ exports[`options validate should throw an error on the "historyApiFallback" opti
190190
object { … }"
191191
`;
192192

193+
exports[`options validate should throw an error on the "host" option with '' value 1`] = `
194+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
195+
- configuration.host should be an non-empty string.
196+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
197+
`;
198+
193199
exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
194200
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
195-
- configuration.host should be one of these:
196-
string | null
197-
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost
198-
Details:
199-
* configuration.host should be a string.
200-
* configuration.host should be a null."
201+
- configuration.host should be a non-empty string.
202+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
203+
`;
204+
205+
exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
206+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
207+
- configuration.host should be a non-empty string.
208+
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
201209
`;
202210

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

test/validate-options.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ const tests = {
175175
failure: [''],
176176
},
177177
host: {
178-
success: ['', 'localhost', '::', '::1', null],
179-
failure: [false],
178+
success: ['localhost', '::', '::1'],
179+
failure: [false, '', null],
180180
},
181181
hot: {
182182
success: [true, 'only'],

0 commit comments

Comments
 (0)