Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: host can't be null or empty string #3352

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,8 @@
"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"
},
"host": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"type": "string",
"minLength": 1,
"description": "Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
},
"hot": {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DevServerPlugin {
host = options.webSocketServer.options.host;
}
// The `host` option is specified
else if (typeof this.options.host !== 'undefined' && this.options.host) {
else if (typeof this.options.host !== 'undefined') {
host = this.options.host;
}
// The `port` option is not specified
Expand Down
20 changes: 14 additions & 6 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,22 @@ exports[`options validate should throw an error on the "historyApiFallback" opti
object { … }"
`;

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be an non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be one of these:
string | null
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* configuration.host should be a string.
* configuration.host should be a null."
- configuration.host should be a non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be a non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down
20 changes: 14 additions & 6 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,22 @@ exports[`options validate should throw an error on the "historyApiFallback" opti
object { … }"
`;

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be an non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "host" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be one of these:
string | null
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* configuration.host should be a string.
* configuration.host should be a null."
- configuration.host should be a non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "host" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.host should be a non-empty string.
-> Specify a host to use. If you want your server to be accessible externally. https://webpack.js.org/configuration/dev-server/#devserverhost"
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down
31 changes: 0 additions & 31 deletions test/server/host-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,6 @@ describe('host option', () => {
afterAll(testServer.close);
});

describe('is null', () => {
beforeAll((done) => {
server = testServer.start(
config,
{
static: {
directory: staticDirectory,
watch: false,
},
host: null,
port,
},
done
);
req = request(server.app);
});

it('server address', () => {
const address = server.server.address();

expect(address.address).toBe('::');
expect(address.port).toBe(port);
});

it('Request to index', (done) => {
req.get('/').expect(200, done);
});

afterAll(testServer.close);
});

describe('is 127.0.0.1 (IPv4)', () => {
beforeAll((done) => {
server = testServer.start(
Expand Down
4 changes: 2 additions & 2 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ const tests = {
failure: [''],
},
host: {
success: ['', 'localhost', '::', '::1', null],
failure: [false],
success: ['localhost', '::', '::1'],
failure: [false, '', null],
},
hot: {
success: [true, 'only'],
Expand Down