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

feat: allow to set the sockjs_url option (only sockjs) #4586

Merged
merged 2 commits into from Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 22 additions & 10 deletions lib/servers/SockJSServer.js
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