/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/next-minimal-starter/src/utils/trpc.ts
45 строк
1 KB
Alex / KATT
feat: rm unstable (#6617)
21 мар 2025, 13:39
Не верифицирован
21 мар 2025, 13:39
0244dee
Код
Авторство
О чём код?
import { httpBatchLink, httpSubscriptionLink, splitLink } from '@trpc/client'; import { createTRPCNext } from '@trpc/next'; import { ssrPrepass } from '@trpc/next/ssrPrepass'; import type { AppRouter } from '../pages/api/trpc/[trpc]'; import { transformer } from './transformer'; function getBaseUrl() { if (typeof window !== 'undefined') { // In the browser, we return a relative URL return ''; } // When rendering on the server, we return an absolute URL // reference for vercel.com if (process.env.VERCEL_URL) { return `https://${process.env.VERCEL_URL}`; } // assume localhost return `http://localhost:${process.env.PORT ?? 3000}`; } export const trpc = createTRPCNext<AppRouter>({ config() { const url = getBaseUrl() + '/api/trpc'; return { links: [ splitLink({ condition: (op) => op.type === 'subscription', true: httpSubscriptionLink({ url, transformer, }), false: httpBatchLink({ url, transformer, }), }), ], }; }, ssr: true, ssrPrepass, transformer, });