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: local websocket url wrong (#1328)

Meier Lukas757263478036
diff --git a/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx b/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
index c08542590..90df364f2 100644
--- a/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
+++ b/apps/nextjs/src/app/[locale]/_client-providers/trpc.tsx
@@ -19,11 +19,23 @@ import superjson from "superjson";
import type { AppRouter } from "@homarr/api";
import { clientApi } from "@homarr/api/client";
+import { env } from "~/env.mjs";
+
+const constructWebsocketUrl = () => {
+ const fallback = "ws://localhost:3001/websockets";
+ if (typeof window === "undefined") {
+ return fallback;
+ }
+
+ if (env.NODE_ENV === "development") {
+ return fallback;
+ }
+
+ return `ws://${window.location.hostname}:${window.location.port}/websockets`;
+};
+
const wsClient = createWSClient({
- url:
- typeof window === "undefined"
- ? "ws://localhost:3001/websockets"
- : `ws://${window.location.hostname}:${window.location.port}/websockets`,
+ url: constructWebsocketUrl(),
});
export function TRPCReactProvider(props: PropsWithChildren) {