level-up/frontend/trpc.ts
Moritz Ruth 88f0632194
All checks were successful
Build / build (push) Successful in 1m14s
Update dependencies, containerize, add build workflow
2025-03-03 00:35:21 +01:00

23 lines
590 B
TypeScript

import { createTRPCProxyClient, createWSClient, wsLink } from "@trpc/client"
import superjson from "superjson"
import type { AppRouter } from "../backend"
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 = "backend." + wsUrl.hostname
}
export const trpcClient = createTRPCProxyClient<AppRouter>({
links: [
wsLink({
client: createWSClient({
url: wsUrl.href
})
})
],
transformer: superjson
})