tRPC 초기 설정

This commit is contained in:
static
2025-11-02 23:09:01 +09:00
parent 328baba395
commit 7779910949
7 changed files with 97 additions and 12 deletions

23
src/trpc/client.ts Normal file
View File

@@ -0,0 +1,23 @@
import { createTRPCClient, httpBatchLink } from "@trpc/client";
import { browser } from "$app/environment";
import type { AppRouter } from "./router.server";
const createClient = (fetch: typeof globalThis.fetch) =>
createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: "/trpc",
fetch,
}),
],
});
let browserClient: ReturnType<typeof createClient>;
export const trpc = (fetch = globalThis.fetch) => {
const client = browserClient ?? createClient(fetch);
if (browser) {
browserClient ??= client;
}
return client;
};