Skip to content

Commit

Permalink
fix: use correct port for https reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Quenby Mitchell committed Feb 16, 2022
1 parent fcf8e8e commit 23dc6f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client-src/utils/createSocketURL.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 23dc6f4

Please sign in to comment.