Skip to content

Commit 69a2fba

Browse files
feat: allow to set the sockjs_url option (only sockjs) using the webSocketServer.options.sockjsUrl option (#4586)
1 parent 5b846cb commit 69a2fba

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

lib/servers/SockJSServer.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,28 @@ module.exports = class SockJSServer extends BaseServer {
4141
constructor(server) {
4242
super(server);
4343

44+
const webSocketServerOptions =
45+
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
46+
(
47+
/** @type {WebSocketServerConfiguration} */
48+
(this.server.options.webSocketServer).options
49+
);
50+
51+
/**
52+
* @param {NonNullable<WebSocketServerConfiguration["options"]>} options
53+
* @returns {string}
54+
*/
55+
const getSockjsUrl = (options) => {
56+
if (typeof options.sockjsUrl !== "undefined") {
57+
return options.sockjsUrl;
58+
}
59+
60+
return "/__webpack_dev_server__/sockjs.bundle.js";
61+
};
62+
4463
this.implementation = sockjs.createServer({
4564
// Use provided up-to-date sockjs-client
46-
sockjs_url: "/__webpack_dev_server__/sockjs.bundle.js",
65+
sockjs_url: getSockjsUrl(webSocketServerOptions),
4766
// Default logger is very annoy. Limit useless logs.
4867
/**
4968
* @param {string} severity
@@ -73,15 +92,8 @@ module.exports = class SockJSServer extends BaseServer {
7392
};
7493

7594
const options = {
76-
.../** @type {WebSocketServerConfiguration} */
77-
(this.server.options.webSocketServer).options,
78-
prefix: getPrefix(
79-
/** @type {NonNullable<WebSocketServerConfiguration["options"]>} */
80-
(
81-
/** @type {WebSocketServerConfiguration} */
82-
(this.server.options.webSocketServer).options
83-
)
84-
),
95+
...webSocketServerOptions,
96+
prefix: getPrefix(webSocketServerOptions),
8597
};
8698

8799
this.implementation.installHandlers(

0 commit comments

Comments
 (0)