Skip to content

Commit

Permalink
feat: allow to set the sockjs_url option (only sockjs) using the …
Browse files Browse the repository at this point in the history
…`webSocketServer.options.sockjsUrl` option (#4586)
  • Loading branch information
alexander-akait authored Sep 27, 2022
1 parent 5b846cb commit 69a2fba
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/servers/SockJSServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,28 @@ module.exports = class SockJSServer extends BaseServer {
constructor(server) {
super(server);

const webSocketServerOptions =
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
(
/** @type {WebSocketServerConfiguration} */
(this.server.options.webSocketServer).options
);

/**
* @param {NonNullable<WebSocketServerConfiguration["options"]>} 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
Expand Down Expand Up @@ -73,15 +92,8 @@ module.exports = class SockJSServer extends BaseServer {
};

const options = {
.../** @type {WebSocketServerConfiguration} */
(this.server.options.webSocketServer).options,
prefix: getPrefix(
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
(
/** @type {WebSocketServerConfiguration} */
(this.server.options.webSocketServer).options
)
),
...webSocketServerOptions,
prefix: getPrefix(webSocketServerOptions),
};

this.implementation.installHandlers(
Expand Down

0 comments on commit 69a2fba

Please sign in to comment.