23 lines
590 B
TypeScript
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
|
|
})
|