import { createTRPCProxyClient, createWSClient, wsLink } from "@trpc/client" import superjson from "superjson" import type { AppRouter } from "./server" const wsUrl = new URL(location.href) wsUrl.protocol = wsUrl.protocol.replace("http", "ws") wsUrl.pathname = "/ws" wsUrl.hash = "" if (import.meta.env.PROD) { wsUrl.hostname = "server." + wsUrl.hostname } export const trpcClient = createTRPCProxyClient({ links: [ wsLink({ client: createWSClient({ url: wsUrl.href }) }) ], transformer: superjson })