♻️ Add env variable validation

This commit is contained in:
Meierschlumpf
2023-07-23 14:18:10 +02:00
parent 18e0e2a8ff
commit 3990c1a4ad
12 changed files with 140 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ import { createTRPCProxyClient, httpBatchLink, loggerLink } from '@trpc/client';
import { createTRPCNext } from '@trpc/next';
import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server';
import superjson from 'superjson';
import { env } from '~/env';
import { type RootRouter } from '~/server/api/root';
const getTrpcConfiguration = () => ({
@@ -26,7 +27,7 @@ const getTrpcConfiguration = () => ({
links: [
loggerLink({
enabled: (opts) =>
process.env.NODE_ENV === 'development' ||
env.NEXT_PUBLIC_NODE_ENV === 'development' ||
(opts.direction === 'down' && opts.result instanceof Error),
}),
httpBatchLink({
@@ -37,8 +38,7 @@ const getTrpcConfiguration = () => ({
const getBaseUrl = () => {
if (typeof window !== 'undefined') return ''; // browser should use relative url
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url
return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost
return `http://localhost:${env.NEXT_PUBLIC_PORT ?? 3000}`; // dev SSR should use localhost
};
/** A set of type-safe react-query hooks for your tRPC API. */