This commit is contained in:
Turbobot
2024-03-21 13:41:16 +08:00
committed by giancarlo
commit bb58169fe9
204 changed files with 26228 additions and 0 deletions

View 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 };