first project commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
|
||||
import { appRouter, createTRPCContext } from '@repo/api';
|
||||
import { resolveUser } from '@/lib/auth';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
const handler = async (req: Request) => {
|
||||
return fetchRequestHandler({
|
||||
endpoint: '/api/trpc',
|
||||
req,
|
||||
router: appRouter,
|
||||
createContext: async () => {
|
||||
const user = await resolveUser();
|
||||
return createTRPCContext({ user, headers: req.headers });
|
||||
},
|
||||
onError({ error, path }) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`[trpc] ${path ?? '<no-path>'}:`, error.message);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in New Issue
Block a user