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

fix: use correct port for https reverse proxy #4293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions client-src/utils/createSocketURL.js
Expand Up @@ -74,6 +74,7 @@ function format(objURL) {
*/
function createSocketURL(parsedURL) {
let { hostname } = parsedURL;
let socketURLPort = parsedURL.port;

// Node.js module parses it as `::`
// `new URL(urlString, [baseURLString])` parses it as '[::]'
Expand All @@ -89,6 +90,9 @@ function createSocketURL(parsedURL) {
self.location.protocol.indexOf("http") === 0
) {
hostname = self.location.hostname;
// If we are using the location.hostname for the hostname, we should use the port from
// the location as well
socketURLPort = self.location.port;
}

let socketURLProtocol = parsedURL.protocol || self.location.protocol;
Expand Down Expand Up @@ -135,8 +139,6 @@ function createSocketURL(parsedURL) {
"localhost"
).replace(/^\[(.*)\]$/, "$1");

let socketURLPort = parsedURL.port;

if (!socketURLPort || socketURLPort === "0") {
socketURLPort = self.location.port;
}
Expand Down
10 changes: 10 additions & 0 deletions test/client/utils/createSocketURL.test.js
Expand Up @@ -100,6 +100,16 @@ describe("'createSocketURL' function ", () => {
[null, "file:///home/user/project/index.html", "ws://localhost/ws"],
[null, "chrome-extension://localhost/", "ws://localhost/ws"],
[null, "file://localhost/", "ws://localhost/ws"],
[
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
"https://app.test.com",
"wss://app.test.com/ws",
],
[
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
"https://app.test.com:7777",
"wss://app.test.com:7777/ws",
],
];

samples.forEach(([__resourceQuery, location, expected]) => {
Expand Down