fix: websockets on https do not work (#1444)
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user