Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

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

Meier Lukas0aa72d118c6c
diff --git a/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx b/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
index 90df364f2..6ddcd97e4 100644
--- a/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
+++ b/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
@@ -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({