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";
|
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 constructWebsocketUrl = () => {
|
||||||
const fallback = "ws://localhost:3001/websockets";
|
const fallback = `${getWebSocketProtocol()}://localhost:3001/websockets`;
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
@@ -31,7 +40,7 @@ const constructWebsocketUrl = () => {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `ws://${window.location.hostname}:${window.location.port}/websockets`;
|
return `${getWebSocketProtocol()}://${window.location.hostname}:${window.location.port}/websockets`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const wsClient = createWSClient({
|
const wsClient = createWSClient({
|
||||||
|
|||||||
Reference in New Issue
Block a user