mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
27 lines
674 B
TypeScript
27 lines
674 B
TypeScript
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
import superjson from "superjson";
|
|
import { browser } from "$app/environment";
|
|
import type { AppRouter } from "./router.server";
|
|
|
|
const createClient = (fetch: typeof globalThis.fetch) =>
|
|
createTRPCClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: "/api/trpc",
|
|
maxURLLength: 4096,
|
|
transformer: superjson,
|
|
fetch,
|
|
}),
|
|
],
|
|
});
|
|
|
|
let browserClient: ReturnType<typeof createClient>;
|
|
|
|
export const trpc = (fetch = globalThis.fetch) => {
|
|
const client = browserClient ?? createClient(fetch);
|
|
if (browser) {
|
|
browserClient ??= client;
|
|
}
|
|
return client;
|
|
};
|