diff --git a/lib/servers/SockJSServer.js b/lib/servers/SockJSServer.js index 5952886ef5..dcadf52c00 100644 --- a/lib/servers/SockJSServer.js +++ b/lib/servers/SockJSServer.js @@ -41,9 +41,28 @@ module.exports = class SockJSServer extends BaseServer { constructor(server) { super(server); + const webSocketServerOptions = + /** @type {NonNullable} */ + ( + /** @type {WebSocketServerConfiguration} */ + (this.server.options.webSocketServer).options + ); + + /** + * @param {NonNullable} options + * @returns {string} + */ + const getSockjsUrl = (options) => { + if (typeof options.sockjsUrl !== "undefined") { + return options.sockjsUrl; + } + + return "/__webpack_dev_server__/sockjs.bundle.js"; + }; + this.implementation = sockjs.createServer({ // Use provided up-to-date sockjs-client - sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js", + sockjs_url: getSockjsUrl(webSocketServerOptions), // Default logger is very annoy. Limit useless logs. /** * @param {string} severity @@ -73,15 +92,8 @@ module.exports = class SockJSServer extends BaseServer { }; const options = { - .../** @type {WebSocketServerConfiguration} */ - (this.server.options.webSocketServer).options, - prefix: getPrefix( - /** @type {NonNullable} */ - ( - /** @type {WebSocketServerConfiguration} */ - (this.server.options.webSocketServer).options - ) - ), + ...webSocketServerOptions, + prefix: getPrefix(webSocketServerOptions), }; this.implementation.installHandlers(