mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
tRPC 초기 설정
This commit is contained in:
23
src/trpc/client.ts
Normal file
23
src/trpc/client.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user