import type { AppRouter } from './routers'; import getUrls from '@/config/urls'; import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'; import { createTRPCNext } from '@trpc/next'; import SuperJSON from 'superjson'; import { isServer } from 'tools/common'; const { BASE_PATH, PORT } = getUrls(); function getBaseUrl() { if (!isServer()) return BASE_PATH; return `http://localhost:${PORT ?? 3000}${BASE_PATH}`; } const url = `${getBaseUrl()}/api/trpc`; export const trpcClient = createTRPCNext({ config({ ctx }) { return { links: [ httpBatchLink({ headers() { return { cookie: ctx?.req?.headers.cookie, }; }, url, }), ], queryClientConfig: { defaultOptions: { queries: { refetchOnMount: false, refetchOnWindowFocus: false, }, }, }, transformer: SuperJSON, }; }, ssr: false, }); export const trpcPureClient = createTRPCProxyClient({ links: [ httpBatchLink({ url, }), ], transformer: SuperJSON, });