import { httpBatchLink } from '@trpc/client/links/httpBatchLink' ; import { loggerLink } from '@trpc/client/links/loggerLink' ; import { withTRPC } from '@trpc/next' ; import { AppType } from 'next/dist/shared/lib/utils' ; import superjson from 'superjson' ; const MyApp = ( { Component , pageProps } ) => { return ( < > < Component { ... pageProps } / > < />); } ; function getBaseUrl ( ) { if ( process . browser ) { return '' ; } if ( process . env . VERCEL_URL ) { return `https://${ process . env . VERCEL_URL }` ; } if ( process . env . RENDER_INTERNAL_HOSTNAME ) { return `http://${ process . env . RENDER_INTERNAL_HOSTNAME }:${ process . env . PORT }` ; } return `http://localhost:${ process . env . PORT ?? 3000 }` ; } export default withTRPC ( { config ( ) { link return { link links : [ loggerLink ( { enabled : ( opts ) => process . env . NODE_ENV === 'development' || ( opts . direction === 'down' && opts . result instanceof Error ) , } ) , httpBatchLink ( { url : `${ getBaseUrl ( ) }/api/trpc` , } ) , ] , link transformer : superjson , } ; } , link ssr : true , /**
     * Set headers or status code when doing SSR
     */ responseMeta ( { clientErrors } ) { if ( clientErrors . length ) { return { status : clientErrors [ 0 ] . data ?. httpStatus ?? 500 , } ; } return { } ; } , } ) ( MyApp ) ;