From f5e737bf9645271f8525070f9ba6de1f476fafd9 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Wed, 2 Jul 2025 00:08:51 +0000 Subject: refactor: Move the trpc endpoint to hono --- packages/api/routes/trpc.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/api/routes/trpc.ts (limited to 'packages/api/routes') diff --git a/packages/api/routes/trpc.ts b/packages/api/routes/trpc.ts new file mode 100644 index 00000000..3d83f64a --- /dev/null +++ b/packages/api/routes/trpc.ts @@ -0,0 +1,28 @@ +import { trpcServer } from "@hono/trpc-server"; +import { Hono } from "hono"; + +import { Context } from "@karakeep/trpc"; +import { appRouter } from "@karakeep/trpc/routers/_app"; + +const trpc = new Hono<{ + Variables: { + ctx: Context; + }; +}>().use( + "/*", + trpcServer({ + endpoint: "/api/trpc", + router: appRouter, + createContext: (_, c) => { + return c.var.ctx; + }, + onError: ({ path, error }) => { + if (process.env.NODE_ENV === "development") { + console.error(`❌ tRPC failed on ${path}`); + } + console.error(error); + }, + }), +); + +export default trpc; -- cgit v1.2.3-70-g09d2