fix: local websocket url wrong (#1328)

This commit is contained in:
Meier Lukas
2024-10-19 10:27:13 +02:00
committed by GitHub
parent 7e219bc86f
commit 7572634780

View File

@@ -19,11 +19,23 @@ import superjson from "superjson";
import type { AppRouter } from "@homarr/api"; import type { AppRouter } from "@homarr/api";
import { clientApi } from "@homarr/api/client"; 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({ const wsClient = createWSClient({
url: url: constructWebsocketUrl(),
typeof window === "undefined"
? "ws://localhost:3001/websockets"
: `ws://${window.location.hostname}:${window.location.port}/websockets`,
}); });
export function TRPCReactProvider(props: PropsWithChildren) { export function TRPCReactProvider(props: PropsWithChildren) {