Skip to content

Commit 216b0d3

Browse files
fix!: host can't be null or empty string (#3352)
1 parent 7169c01 commit 216b0d3

6 files changed

+33
-54
lines changed

lib/options.json

+2-8
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

+1-1
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

+14-6
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

+14-6
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/server/host-option.test.js

-31
Original file line numberDiff line numberDiff line change
@@ -78,37 +78,6 @@ describe('host option', () => {
7878
afterAll(testServer.close);
7979
});
8080

81-
describe('is null', () => {
82-
beforeAll((done) => {
83-
server = testServer.start(
84-
config,
85-
{
86-
static: {
87-
directory: staticDirectory,
88-
watch: false,
89-
},
90-
host: null,
91-
port,
92-
},
93-
done
94-
);
95-
req = request(server.app);
96-
});
97-
98-
it('server address', () => {
99-
const address = server.server.address();
100-
101-
expect(address.address).toBe('::');
102-
expect(address.port).toBe(port);
103-
});
104-
105-
it('Request to index', (done) => {
106-
req.get('/').expect(200, done);
107-
});
108-
109-
afterAll(testServer.close);
110-
});
111-
11281
describe('is 127.0.0.1 (IPv4)', () => {
11382
beforeAll((done) => {
11483
server = testServer.start(

test/validate-options.test.js

+2-2
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)