Initial commit

This commit is contained in:
Meier Lukas
2023-12-08 22:35:15 +01:00
commit a2cedf73c0
74 changed files with 15357 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
export { GET, POST } from "@acme/auth";
export const runtime = "edge";

View File

@@ -0,0 +1,42 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { appRouter, createTRPCContext } from "@acme/api";
import { auth } from "@acme/auth";
export const runtime = "edge";
/**
* Configure basic CORS headers
* You should extend this to match your needs
*/
function setCorsHeaders(res: Response) {
res.headers.set("Access-Control-Allow-Origin", "*");
res.headers.set("Access-Control-Request-Method", "*");
res.headers.set("Access-Control-Allow-Methods", "OPTIONS, GET, POST");
res.headers.set("Access-Control-Allow-Headers", "*");
}
export function OPTIONS() {
const response = new Response(null, {
status: 204,
});
setCorsHeaders(response);
return response;
}
const handler = auth(async (req) => {
const response = await fetchRequestHandler({
endpoint: "/api/trpc",
router: appRouter,
req,
createContext: () => createTRPCContext({ auth: req.auth, req }),
onError({ error, path }) {
console.error(`>>> tRPC Error on '${path}'`, error);
},
});
setCorsHeaders(response);
return response;
});
export { handler as GET, handler as POST };