/
githubmirror
/
trpc
Обзор
Документация
Войти
/
githubmirror
/
trpc
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/next-edge-runtime/src/utils/trpc.ts
31 строка
733 B
Alex / KATT
fix(next): add `ssrPrepass`-callback to avoid bundling of `react-dom` (#5426)
02 фев 2024, 16:42
Не верифицирован
02 фев 2024, 16:42
d61ece3
Код
Авторство
О чём код?
import { httpBatchLink } from '@trpc/client'; import { createTRPCNext } from '@trpc/next'; import type { AppRouter } from '../pages/api/trpc/[trpc]'; 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() { return { links: [ httpBatchLink({ url: getBaseUrl() + '/api/trpc', }), ], }; }, });