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() { return { links: [ httpBatchLink({ url, }), ], transformer: SuperJSON, }; }, }); export const trpcPureClient = createTRPCProxyClient({ links: [ httpBatchLink({ url, }), ], transformer: SuperJSON, });