fix: websockets on https do not work (#1444)

This commit is contained in:
Meier Lukas
2024-11-08 21:30:05 +01:00
committed by GitHub
parent 2306ecda9f
commit 0aa72d118c

View File

@@ -21,8 +21,17 @@ import { clientApi } from "@homarr/api/client";
import { env } from "~/env.mjs";
const getWebSocketProtocol = () => {
// window is not defined on server side
if (typeof window === "undefined") {
return "ws";
}
return window.location.protocol === "https:" ? "wss" : "ws";
};
const constructWebsocketUrl = () => {
const fallback = "ws://localhost:3001/websockets";
const fallback = `${getWebSocketProtocol()}://localhost:3001/websockets`;
if (typeof window === "undefined") {
return fallback;
}
@@ -31,7 +40,7 @@ const constructWebsocketUrl = () => {
return fallback;
}
return `ws://${window.location.hostname}:${window.location.port}/websockets`;
return `${getWebSocketProtocol()}://${window.location.hostname}:${window.location.port}/websockets`;
};
const wsClient = createWSClient({