Skip to content

Commit d70a421

Browse files
snitin315alexander-akait
authored andcommitted
fix: show warning using custom hostname and port with sockjs (#4848)
1 parent 01f35c1 commit d70a421

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/Server.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,27 @@ class Server {
555555
let hostname;
556556

557557
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
558-
// TODO show warning about this
559558
const isSockJSType = webSocketServer.type === "sockjs";
559+
const isWebSocketServerHostDefined =
560+
typeof webSocketServer.options.host !== "undefined";
561+
const isWebSocketServerPortDefined =
562+
typeof webSocketServer.options.port !== "undefined";
563+
564+
if (
565+
isSockJSType &&
566+
(isWebSocketServerHostDefined || isWebSocketServerPortDefined)
567+
) {
568+
this.logger.warn(
569+
"SockJS only supports client mode and does not support custom hostname and port options. Please consider using 'ws' if you need to customize these options."
570+
);
571+
}
560572

561573
// We are proxying dev server and need to specify custom `hostname`
562574
if (typeof webSocketURL.hostname !== "undefined") {
563575
hostname = webSocketURL.hostname;
564576
}
565577
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
566-
else if (
567-
typeof webSocketServer.options.host !== "undefined" &&
568-
!isSockJSType
569-
) {
578+
else if (isWebSocketServerHostDefined && !isSockJSType) {
570579
hostname = webSocketServer.options.host;
571580
}
572581
// The `host` option is specified
@@ -588,10 +597,7 @@ class Server {
588597
port = webSocketURL.port;
589598
}
590599
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
591-
else if (
592-
typeof webSocketServer.options.port !== "undefined" &&
593-
!isSockJSType
594-
) {
600+
else if (isWebSocketServerPortDefined && !isSockJSType) {
595601
port = webSocketServer.options.port;
596602
}
597603
// The `port` option is specified

types/lib/Server.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,14 +1229,15 @@ declare class Server {
12291229
};
12301230
StaticObject: {
12311231
type: string;
1232-
additionalProperties: boolean;
1232+
/** @type {MultiCompiler} */ additionalProperties: boolean;
12331233
properties: {
12341234
directory: {
12351235
type: string;
12361236
minLength: number;
12371237
description: string;
12381238
link: string;
12391239
};
1240+
/** @type {MultiCompiler} */
12401241
staticOptions: {
12411242
type: string;
12421243
link: string;

0 commit comments

Comments
 (0)