aboutsummaryrefslogtreecommitdiffstats
path: root/packages/api/index.ts
blob: 2eb22d8f87f547c1a3abb5cf8e19bf3c2a285120 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Hono } from "hono";
import { logger } from "hono/logger";
import { poweredBy } from "hono/powered-by";

import { Context } from "@karakeep/trpc";

import trpcAdapter from "./middlewares/trpcAdapter";
import assets from "./routes/assets";
import bookmarks from "./routes/bookmarks";
import health from "./routes/health";
import highlights from "./routes/highlights";
import lists from "./routes/lists";
import publicRoute from "./routes/public";
import rss from "./routes/rss";
import tags from "./routes/tags";
import trpc from "./routes/trpc";
import users from "./routes/users";

const v1 = new Hono<{
  Variables: {
    ctx: Context;
  };
}>()
  .route("/highlights", highlights)
  .route("/bookmarks", bookmarks)
  .route("/lists", lists)
  .route("/tags", tags)
  .route("/users", users)
  .route("/assets", assets)
  .route("/rss", rss);

const app = new Hono<{
  Variables: {
    // This is going to be coming from the web app
    ctx: Context;
  };
}>()
  .use(logger())
  .use(poweredBy())
  .use(async (c, next) => {
    // Ensure that the ctx is set
    if (!c.var.ctx) {
      throw new Error("Context is not set");
    }
    await next();
  })
  .use(trpcAdapter)
  .route("/health", health)
  .route("/trpc", trpc)
  .route("/v1", v1)
  .route("/assets", assets)
  .route("/public", publicRoute);

export default app;