Skip to content

Commit 23dc6f4

Browse files
author
Quenby Mitchell
committed
fix: use correct port for https reverse proxy
1 parent fcf8e8e commit 23dc6f4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

client-src/utils/createSocketURL.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function format(objURL) {
7474
*/
7575
function createSocketURL(parsedURL) {
7676
let { hostname } = parsedURL;
77+
let socketURLPort = parsedURL.port;
7778

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

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

138-
let socketURLPort = parsedURL.port;
139-
140142
if (!socketURLPort || socketURLPort === "0") {
141143
socketURLPort = self.location.port;
142144
}

test/client/utils/createSocketURL.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ describe("'createSocketURL' function ", () => {
100100
[null, "file:///home/user/project/index.html", "ws://localhost/ws"],
101101
[null, "chrome-extension://localhost/", "ws://localhost/ws"],
102102
[null, "file://localhost/", "ws://localhost/ws"],
103+
[
104+
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
105+
"https://app.test.com",
106+
"wss://app.test.com/ws",
107+
],
108+
[
109+
"?protocol=ws:&hostname=0.0.0.0&port=3000&pathname=/ws&logging=none&reconnect=10",
110+
"https://app.test.com:7777",
111+
"wss://app.test.com:7777/ws",
112+
],
103113
];
104114

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

0 commit comments

Comments
 (0)