Assume wss:// with no port when frontend is HTTPS (#2129)
This commit is contained in:
parent
6a7bab8416
commit
53d4c438ed
@ -12,6 +12,9 @@ import { initialEvents } from "utils/context.js"
|
|||||||
const EVENTURL = env.EVENT
|
const EVENTURL = env.EVENT
|
||||||
const UPLOADURL = env.UPLOAD
|
const UPLOADURL = env.UPLOAD
|
||||||
|
|
||||||
|
// These hostnames indicate that the backend and frontend are reachable via the same domain.
|
||||||
|
const SAME_DOMAIN_HOSTNAMES = ["localhost", "0.0.0.0", "::", "0:0:0:0:0:0:0:0"]
|
||||||
|
|
||||||
// Global variable to hold the token.
|
// Global variable to hold the token.
|
||||||
let token;
|
let token;
|
||||||
|
|
||||||
@ -74,12 +77,13 @@ export const getToken = () => {
|
|||||||
export const getEventURL = () => {
|
export const getEventURL = () => {
|
||||||
// Get backend URL object from the endpoint.
|
// Get backend URL object from the endpoint.
|
||||||
const endpoint = new URL(EVENTURL);
|
const endpoint = new URL(EVENTURL);
|
||||||
if (endpoint.hostname === "localhost") {
|
if (SAME_DOMAIN_HOSTNAMES.includes(endpoint.hostname)) {
|
||||||
// If the backend URL references localhost, and the frontend is not on localhost,
|
// Use the frontend domain to access the backend
|
||||||
// then use the frontend host.
|
|
||||||
const frontend_hostname = window.location.hostname;
|
const frontend_hostname = window.location.hostname;
|
||||||
if (frontend_hostname !== "localhost") {
|
endpoint.hostname = frontend_hostname;
|
||||||
endpoint.hostname = frontend_hostname;
|
if (window.location.protocol === "https:" && endpoint.protocol === "ws:") {
|
||||||
|
endpoint.protocol = "wss:";
|
||||||
|
endpoint.port = ""; // Assume websocket is on https port via load balancer.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return endpoint
|
return endpoint
|
||||||
|
Loading…
Reference in New Issue
Block a user