From 04572a8e5081b1e4871e273cde9dbaaa44c52fe0 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 21:43:44 +0000 Subject: structure: Create apps dir and copy tooling dir from t3-turbo repo --- packages/web/app/api/trpc/[trpc]/route.ts | 36 ------------------------------- 1 file changed, 36 deletions(-) delete mode 100644 packages/web/app/api/trpc/[trpc]/route.ts (limited to 'packages/web/app/api/trpc') diff --git a/packages/web/app/api/trpc/[trpc]/route.ts b/packages/web/app/api/trpc/[trpc]/route.ts deleted file mode 100644 index b6753101..00000000 --- a/packages/web/app/api/trpc/[trpc]/route.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; -import { appRouter } from "@hoarder/trpc/routers/_app"; -import { createContext } from "@/server/api/client"; -import { authenticateApiKey } from "@hoarder/trpc/auth"; -import { db } from "@hoarder/db"; - -const handler = (req: Request) => - fetchRequestHandler({ - endpoint: "/api/trpc", - req, - router: appRouter, - onError: ({ path, error }) => { - if (process.env.NODE_ENV === "development") { - console.error(`❌ tRPC failed on ${path}`); - } - console.error(error); - }, - - createContext: async (opts) => { - // TODO: This is a hack until we offer a proper REST API instead of the trpc based one. - // Check if the request has an Authorization token, if it does, assume that API key authentication is requested. - const authorizationHeader = opts.req.headers.get("Authorization"); - if (authorizationHeader && authorizationHeader.startsWith("Bearer ")) { - const token = authorizationHeader.split(" ")[1]; - try { - const user = await authenticateApiKey(token); - return { user, db }; - } catch (e) { - // Fallthrough to cookie-based auth - } - } - - return createContext(); - }, - }); -export { handler as GET, handler as POST }; -- cgit v1.2.3-70-g09d2