UNPKG

trpc-sveltekit

Version:

SvelteKit adapter for tRPC.io, working with Node.js, Vercel and Netlify

25 lines (24 loc) 898 B
import { httpBatchLink, createTRPCProxyClient as internalCreateTRPCClient } from '@trpc/client'; /** * Create a tRPC client. * @see https://trpc.io/docs/vanilla */ export function createTRPCClient({ links, url = '/trpc', transformer, init, headers } = { url: '/trpc' }) { if (links) return internalCreateTRPCClient({ transformer, links }); if (typeof window === 'undefined' && !init) { throw new Error('Calling createTRPCClient() on the server requires passing a valid LoadEvent argument'); } return internalCreateTRPCClient({ transformer, links: [ httpBatchLink({ url: typeof window === 'undefined' ? `${init.url.origin}${url}` : `${location.origin}${url}`, fetch: typeof window === 'undefined' ? init.fetch : init?.fetch ?? window.fetch, headers }) ] }); }