aboutsummaryrefslogtreecommitdiffstats
path: root/packages/api/routes/trpc.ts
blob: 3d83f64aeecefb776a46dbc98edf47d1a7dbf680 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;