From 3a7f0e6488a6ed87c353dac3ad69351d78738121 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 27 May 2021 19:37:08 +0530 Subject: [PATCH 1/5] feat: allow string value for `port` --- lib/options.json | 10 +- lib/utils/normalizeOptions.js | 20 ++- .../validate-options.test.js.snap.webpack4 | 15 ++- .../validate-options.test.js.snap.webpack5 | 15 ++- test/e2e/web-socket-server-and-url.test.js | 35 +++++ .../normalizeOptions.test.js.snap.webpack4 | 122 +++++++++++++++++- .../normalizeOptions.test.js.snap.webpack5 | 120 +++++++++++++++++ test/server/utils/normalizeOptions.test.js | 58 +++++++++ test/validate-options.test.js | 3 + 9 files changed, 387 insertions(+), 11 deletions(-) diff --git a/lib/options.json b/lib/options.json index 77adb76cae..554f8fe48d 100644 --- a/lib/options.json +++ b/lib/options.json @@ -296,7 +296,15 @@ "description": "Tells clients connected to devServer to use the provided host." }, "port": { - "type": "number", + "anyOf": [ + { + "type": "number" + }, + { + "type": "string", + "minLength": 1 + } + ], "description": "Tells clients connected to devServer to use the provided port." }, "path": { diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index f5303b00ec..3e4f67e600 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -74,6 +74,10 @@ function normalizeOptions(compiler, options, logger) { options.liveReload = typeof options.liveReload !== 'undefined' ? options.liveReload : true; + if (typeof options.port === 'string' && options.port !== 'auto') { + options.port = Number(options.port); + } + const defaultWebSocketServerType = 'ws'; const defaultWebSocketServerOptions = { path: '/ws' }; @@ -91,6 +95,15 @@ function normalizeOptions(compiler, options, logger) { options: defaultWebSocketServerOptions, }; } else { + if ( + options.webSocketServer.options && + typeof options.webSocketServer.options.port === 'string' + ) { + options.webSocketServer.options.port = Number( + options.webSocketServer.options.port + ); + } + options.webSocketServer = { type: options.webSocketServer.type || defaultWebSocketServerType, options: { @@ -111,9 +124,14 @@ function normalizeOptions(compiler, options, logger) { options.client.webSocketURL = { host: parsedURL.hostname, - port: parsedURL.port, + port: Number(parsedURL.port), path: parsedURL.pathname, }; + } else if ( + typeof options.client.webSocketURL === 'object' && + typeof options.client.webSocketURL.port === 'string' + ) { + options.client.webSocketURL.port = Number(options.client.webSocketURL.port); } // Enable client overlay by default diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 33b486a843..a69d352d81 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -150,14 +150,21 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":""}}' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - - configuration.client.webSocketURL.port should be a number. - -> Tells clients connected to devServer to use the provided port." + - configuration.client.webSocketURL.port should be an non-empty string." `; exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - - configuration.client.webSocketURL.port should be a number. - -> Tells clients connected to devServer to use the provided port." + - configuration.client.webSocketURL should be one of these: + non-empty string | object { host?, port?, path? } + -> When using dev server and you're proxying dev-server, the client script does not always know where to connect to. + Details: + * configuration.client.webSocketURL.port should be one of these: + number | non-empty string + -> Tells clients connected to devServer to use the provided port. + Details: + * configuration.client.webSocketURL.port should be a number. + * configuration.client.webSocketURL.port should be a non-empty string." `; exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = ` diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 33b486a843..a69d352d81 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -150,14 +150,21 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":""}}' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - - configuration.client.webSocketURL.port should be a number. - -> Tells clients connected to devServer to use the provided port." + - configuration.client.webSocketURL.port should be an non-empty string." `; exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = ` "ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - - configuration.client.webSocketURL.port should be a number. - -> Tells clients connected to devServer to use the provided port." + - configuration.client.webSocketURL should be one of these: + non-empty string | object { host?, port?, path? } + -> When using dev server and you're proxying dev-server, the client script does not always know where to connect to. + Details: + * configuration.client.webSocketURL.port should be one of these: + number | non-empty string + -> Tells clients connected to devServer to use the provided port. + Details: + * configuration.client.webSocketURL.port should be a number. + * configuration.client.webSocketURL.port should be a non-empty string." `; exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = ` diff --git a/test/e2e/web-socket-server-and-url.test.js b/test/e2e/web-socket-server-and-url.test.js index d6fc80f379..5c00a09000 100644 --- a/test/e2e/web-socket-server-and-url.test.js +++ b/test/e2e/web-socket-server-and-url.test.js @@ -316,6 +316,41 @@ for (const webSocketServerType of webSocketServerTypes) { }); }); + describe('should work with custom client port as string', () => { + beforeAll((done) => { + const options = { + webSocketServer: webSocketServerType, + port: port2, + host: '0.0.0.0', + client: { + webSocketURL: { + port: `${port3}`, + }, + }, + }; + + testServer.startAwaitingCompilation(config, options, done); + }); + + afterAll(testServer.close); + + describe('browser client', () => { + it('uses correct port and path', (done) => { + runBrowser().then(({ page, browser }) => { + waitForTest(browser, page, /ws/, (websocketUrl) => { + expect(websocketUrl).toContain( + `${websocketUrlProtocol}://localhost:${port3}/ws` + ); + + done(); + }); + + page.goto(`http://localhost:${port2}/main`); + }); + }); + }); + }); + describe('should work with custom client host', () => { beforeAll((done) => { const options = { diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 index 9f022c76f4..571c9eaf29 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +git// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`normalizeOptions allowedHosts is set should set correct options 1`] = ` Object { @@ -219,7 +219,91 @@ Object { } `; +<<<<<<< HEAD exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` +======= +<<<<<<< HEAD +exports[`normalizeOptions client.transport ws string should set correct options 1`] = ` +======= +exports[`normalizeOptions client.transport ws string and webSocketServer object should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "transport": "ws", + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "host": "myhost", + "path": "/ws", + "port": 8080, + }, + "type": "ws", + }, +} +`; + +exports[`normalizeOptions client.transport ws string and webSocketServer object with port as string should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "transport": "ws", + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "host": "myhost", + "path": "/ws", + "port": 8080, + }, + "type": "ws", + }, +} +`; + +exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` +>>>>>>> 8b6c9cf... fix: normalize port +>>>>>>> feat: allow string value for `port` Object { "allowedHosts": "auto", "client": Object { @@ -575,6 +659,42 @@ Object { } `; +exports[`normalizeOptions port string should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "port": 9000, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + exports[`normalizeOptions single compiler watchOptions is object should set correct options 1`] = ` Object { "allowedHosts": "auto", diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 index 9f022c76f4..87617dee80 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 @@ -219,7 +219,91 @@ Object { } `; +<<<<<<< HEAD exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` +======= +<<<<<<< HEAD +exports[`normalizeOptions client.transport ws string should set correct options 1`] = ` +======= +exports[`normalizeOptions client.transport ws string and webSocketServer object should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "transport": "ws", + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "host": "myhost", + "path": "/ws", + "port": 8080, + }, + "type": "ws", + }, +} +`; + +exports[`normalizeOptions client.transport ws string and webSocketServer object with port as string should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "transport": "ws", + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "host": "myhost", + "path": "/ws", + "port": 8080, + }, + "type": "ws", + }, +} +`; + +exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` +>>>>>>> 8b6c9cf... fix: normalize port +>>>>>>> feat: allow string value for `port` Object { "allowedHosts": "auto", "client": Object { @@ -575,6 +659,42 @@ Object { } `; +exports[`normalizeOptions port string should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "port": 9000, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + exports[`normalizeOptions single compiler watchOptions is object should set correct options 1`] = ` Object { "allowedHosts": "auto", diff --git a/test/server/utils/normalizeOptions.test.js b/test/server/utils/normalizeOptions.test.js index 8142555917..28518a448f 100644 --- a/test/server/utils/normalizeOptions.test.js +++ b/test/server/utils/normalizeOptions.test.js @@ -12,6 +12,14 @@ describe('normalizeOptions', () => { options: {}, optionsResults: null, }, + { + title: 'port string', + multiCompiler: false, + options: { + port: '9000', + }, + optionsResults: null, + }, { title: 'client.transport sockjs string', multiCompiler: false, @@ -59,6 +67,43 @@ describe('normalizeOptions', () => { }, optionsResults: null, }, + { + title: 'client.transport ws string and webSocketServer object', + multiCompiler: false, + options: { + client: { + transport: 'ws', + }, + webSocketServer: { + type: 'ws', + options: { + host: 'myhost', + port: 8080, + path: '/ws', + }, + }, + }, + optionsResults: null, + }, + { + title: + 'client.transport ws string and webSocketServer object with port as string', + multiCompiler: false, + options: { + client: { + transport: 'ws', + }, + webSocketServer: { + type: 'ws', + options: { + host: 'myhost', + port: '8080', + path: '/ws', + }, + }, + }, + optionsResults: null, + }, { title: 'client custom transport path', multiCompiler: false, @@ -82,6 +127,19 @@ describe('normalizeOptions', () => { }, optionsResults: null, }, + { + title: 'client host and string port', + multiCompiler: false, + options: { + client: { + webSocketURL: { + host: 'my.host', + port: '9000', + }, + }, + }, + optionsResults: null, + }, { title: 'client path', multiCompiler: false, diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 4d66f884b9..c5db1a006e 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -91,6 +91,9 @@ const tests = { { webSocketURL: { port: 8080 }, }, + { + webSocketURL: { port: '8080' }, + }, { webSocketURL: { path: '' }, }, From a6e65e948b874cb94e35e97b32017c4cc8439c1a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 28 May 2021 17:42:32 +0530 Subject: [PATCH 2/5] test: update snaps --- .../normalizeOptions.test.js.snap.webpack4 | 48 +++++++++++++++---- .../normalizeOptions.test.js.snap.webpack5 | 46 ++++++++++++++---- 2 files changed, 77 insertions(+), 17 deletions(-) diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 index 571c9eaf29..91a974cfcd 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4 @@ -1,4 +1,4 @@ -git// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`normalizeOptions allowedHosts is set should set correct options 1`] = ` Object { @@ -109,6 +109,44 @@ Object { } `; +exports[`normalizeOptions client host and string port should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "webSocketURL": Object { + "host": "my.host", + "port": 9000, + }, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + exports[`normalizeOptions client path should set correct options 1`] = ` Object { "allowedHosts": "auto", @@ -219,12 +257,6 @@ Object { } `; -<<<<<<< HEAD -exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` -======= -<<<<<<< HEAD -exports[`normalizeOptions client.transport ws string should set correct options 1`] = ` -======= exports[`normalizeOptions client.transport ws string and webSocketServer object should set correct options 1`] = ` Object { "allowedHosts": "auto", @@ -302,8 +334,6 @@ Object { `; exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` ->>>>>>> 8b6c9cf... fix: normalize port ->>>>>>> feat: allow string value for `port` Object { "allowedHosts": "auto", "client": Object { diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 index 87617dee80..91a974cfcd 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack5 @@ -109,6 +109,44 @@ Object { } `; +exports[`normalizeOptions client host and string port should set correct options 1`] = ` +Object { + "allowedHosts": "auto", + "client": Object { + "hotEntry": true, + "overlay": true, + "webSocketURL": Object { + "host": "my.host", + "port": 9000, + }, + }, + "compress": true, + "devMiddleware": Object {}, + "hot": true, + "liveReload": true, + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "CWD", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + exports[`normalizeOptions client path should set correct options 1`] = ` Object { "allowedHosts": "auto", @@ -219,12 +257,6 @@ Object { } `; -<<<<<<< HEAD -exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` -======= -<<<<<<< HEAD -exports[`normalizeOptions client.transport ws string should set correct options 1`] = ` -======= exports[`normalizeOptions client.transport ws string and webSocketServer object should set correct options 1`] = ` Object { "allowedHosts": "auto", @@ -302,8 +334,6 @@ Object { `; exports[`normalizeOptions client.transport ws string and webSocketServer ws string should set correct options 1`] = ` ->>>>>>> 8b6c9cf... fix: normalize port ->>>>>>> feat: allow string value for `port` Object { "allowedHosts": "auto", "client": Object { From 5adf5d3a4de11451ff65c00d63c0d89d6f4e2ddf Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 28 May 2021 17:49:57 +0530 Subject: [PATCH 3/5] test: e2e --- test/e2e/web-socket-server-and-url.test.js | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/e2e/web-socket-server-and-url.test.js b/test/e2e/web-socket-server-and-url.test.js index 5c00a09000..2cc0d286f2 100644 --- a/test/e2e/web-socket-server-and-url.test.js +++ b/test/e2e/web-socket-server-and-url.test.js @@ -351,6 +351,47 @@ for (const webSocketServerType of webSocketServerTypes) { }); }); + describe('should work with custom client.webSocketURL.port and webSocketServer.options.port both as string', () => { + beforeAll((done) => { + const options = { + webSocketServer: { + type: webSocketServerType, + options: { + host: '0.0.0.0', + port: `${port2}`, + }, + }, + port: port2, + host: '0.0.0.0', + client: { + webSocketURL: { + port: `${port3}`, + }, + }, + }; + + testServer.startAwaitingCompilation(config, options, done); + }); + + afterAll(testServer.close); + + describe('browser client', () => { + it('uses correct port and path', (done) => { + runBrowser().then(({ page, browser }) => { + waitForTest(browser, page, /ws/, (websocketUrl) => { + expect(websocketUrl).toContain( + `${websocketUrlProtocol}://localhost:${port3}/ws` + ); + + done(); + }); + + page.goto(`http://localhost:${port2}/main`); + }); + }); + }); + }); + describe('should work with custom client host', () => { beforeAll((done) => { const options = { From 7de1334966dacd29aa8f99924800c1f71fa1011d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 28 May 2021 18:04:44 +0530 Subject: [PATCH 4/5] refactor: code --- lib/utils/normalizeOptions.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index 3e4f67e600..c00ec3392d 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -95,15 +95,6 @@ function normalizeOptions(compiler, options, logger) { options: defaultWebSocketServerOptions, }; } else { - if ( - options.webSocketServer.options && - typeof options.webSocketServer.options.port === 'string' - ) { - options.webSocketServer.options.port = Number( - options.webSocketServer.options.port - ); - } - options.webSocketServer = { type: options.webSocketServer.type || defaultWebSocketServerType, options: { @@ -111,6 +102,10 @@ function normalizeOptions(compiler, options, logger) { ...options.webSocketServer.options, }, }; + + if (typeof options.webSocketServer.port === 'string') { + options.webSocketServer.port = Number(options.webSocketServer.port); + } } if (!options.client) { @@ -127,12 +122,11 @@ function normalizeOptions(compiler, options, logger) { port: Number(parsedURL.port), path: parsedURL.pathname, }; - } else if ( - typeof options.client.webSocketURL === 'object' && - typeof options.client.webSocketURL.port === 'string' - ) { - options.client.webSocketURL.port = Number(options.client.webSocketURL.port); - } + } else if (typeof options.client.webSocketURL.port === 'string') { + options.client.webSocketURL.port = Number( + options.client.webSocketURL.port + ); + } // Enable client overlay by default if (typeof options.client.overlay === 'undefined') { From b89d4fe52e2f6963f6c839a90882a55d90b0a9b5 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 28 May 2021 20:15:05 +0530 Subject: [PATCH 5/5] fix: typo --- lib/utils/normalizeOptions.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index c00ec3392d..2b4133dff0 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -103,8 +103,10 @@ function normalizeOptions(compiler, options, logger) { }, }; - if (typeof options.webSocketServer.port === 'string') { - options.webSocketServer.port = Number(options.webSocketServer.port); + if (typeof options.webSocketServer.options.port === 'string') { + options.webSocketServer.options.port = Number( + options.webSocketServer.options.port + ); } } @@ -123,10 +125,8 @@ function normalizeOptions(compiler, options, logger) { path: parsedURL.pathname, }; } else if (typeof options.client.webSocketURL.port === 'string') { - options.client.webSocketURL.port = Number( - options.client.webSocketURL.port - ); - } + options.client.webSocketURL.port = Number(options.client.webSocketURL.port); + } // Enable client overlay by default if (typeof options.client.overlay === 'undefined') {