import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import { appRouter } from "@cf/providers/trpc";const handler = (req: Request) => fetchRequestHandler({ endpoint: "/api/trpc2", router: appRouter, req, createContext: async () => ({}), });export const POST = handler;export const GET = handler;
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";import { appRouter } from "@cf/providers/trpc";export const GET = (req: Request) => fetchRequestHandler({ endpoint: "/api/trpc2", router: appRouter, req, createContext: async () => ({}), });
export const trpc = createTRPCReact<AppRouter>({ unstable_overrides: { useMutation: { async onSuccess(opts) { await opts.originalFn(); await opts.queryClient.invalidateQueries(); }, }, },});const getBaseUrl = (): string => { const env = getEnvVariableOrDefault("NODE_ENV", ""); const VERCEL_URL = getEnvVariableOrDefault("VERCEL_URL", ""); const PORT = getEnvVariableOrDefault("PORT", "3000"); if (env === "test") return `http://localhost:${PORT}`; if (typeof window !== "undefined") return ""; if (VERCEL_URL) return `https://${VERCEL_URL}`; return `http://localhost:${PORT}`;};export type TRPCProviderProps = { children: ReactNode;};export const TrpcProvider: FunctionComponent<TRPCProviderProps> = ({ children,}) => { const [queryClient] = useState(() => new QueryClient()); const [trpcClient] = useState(() => trpc.createClient({ links: [ loggerLink({ enabled: () => true, }), httpBatchLink({ url: `${getBaseUrl()}/api/trpc2`, }), ], transformer: superJson, }), ); return ( <trpc.Provider client={trpcClient} queryClient={queryClient}> <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> </trpc.Provider> );};