feat(create-turbo): create https://github.com/juliusmarminge/acme-corp
This commit is contained in:
31
apps/nextjs/src/app/api/trpc/lambda/[trpc]/route.ts
Normal file
31
apps/nextjs/src/app/api/trpc/lambda/[trpc]/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { NextRequest } from "next/server";
|
||||
import { getAuth } from "@clerk/nextjs/server";
|
||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
||||
|
||||
import { createTRPCContext } from "@acme/api";
|
||||
import { lambdaRouter } from "@acme/api/lambda";
|
||||
|
||||
// Stripe is incompatible with Edge runtimes due to using Node.js events
|
||||
// export const runtime = "edge";
|
||||
|
||||
const createContext = async (req: NextRequest) => {
|
||||
return createTRPCContext({
|
||||
headers: req.headers,
|
||||
auth: getAuth(req),
|
||||
req,
|
||||
});
|
||||
};
|
||||
|
||||
const handler = (req: NextRequest) =>
|
||||
fetchRequestHandler({
|
||||
endpoint: "/api/trpc/lambda",
|
||||
router: lambdaRouter,
|
||||
req: req,
|
||||
createContext: () => createContext(req),
|
||||
onError: ({ error, path }) => {
|
||||
console.log("Error in tRPC handler (lambda) on path", path);
|
||||
console.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in New Issue
Block a user