WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at root/atb-56-theme-caching-layer 67 lines 2.3 kB view raw
1import { Hono } from "hono"; 2import type { AppContext } from "../lib/app-context.js"; 3import { healthRoutes, createHealthRoutes } from "./health.js"; 4import { createForumRoutes } from "./forum.js"; 5import { createCategoriesRoutes } from "./categories.js"; 6import { createBoardsRoutes } from "./boards.js"; 7import { createTopicsRoutes } from "./topics.js"; 8import { createPostsRoutes } from "./posts.js"; 9import { createAuthRoutes } from "./auth.js"; 10import { createAdminRoutes } from "./admin.js"; 11import { createModRoutes } from "./mod.js"; 12import { createThemesRoutes, createThemePolicyRoutes } from "./themes.js"; 13 14/** 15 * Factory function that creates all API routes with access to app context. 16 */ 17export function createApiRoutes(ctx: AppContext) { 18 return new Hono() 19 .route("/healthz", healthRoutes) 20 .route("/", createHealthRoutes(ctx)) 21 .route("/auth", createAuthRoutes(ctx)) 22 .route("/forum", createForumRoutes(ctx)) 23 .route("/categories", createCategoriesRoutes(ctx)) 24 .route("/boards", createBoardsRoutes(ctx)) 25 .route("/topics", createTopicsRoutes(ctx)) 26 .route("/posts", createPostsRoutes(ctx)) 27 .route("/admin", createAdminRoutes(ctx)) 28 .route("/mod", createModRoutes(ctx)) 29 .route("/themes", createThemesRoutes(ctx)) 30 .route("/theme-policy", createThemePolicyRoutes(ctx)); 31} 32 33// Export stub routes for tests that don't need database access 34const stubForumRoutes = new Hono().get("/", (c) => 35 c.json({ 36 name: "My atBB Forum", 37 description: "A forum on the ATmosphere", 38 did: "did:plc:placeholder", 39 }) 40); 41 42const stubCategoriesRoutes = new Hono().get("/", (c) => 43 c.json({ categories: [] }) 44); 45 46const stubBoardsRoutes = new Hono().get("/", (c) => 47 c.json({ boards: [] }) 48); 49 50const stubTopicsRoutes = new Hono() 51 .get("/:id", (c) => { 52 const { id } = c.req.param(); 53 return c.json({ topicId: id, post: null, replies: [] }); 54 }) 55 .post("/", (c) => c.json({ error: "not implemented" }, 501)); 56 57const stubPostsRoutes = new Hono().post("/", (c) => 58 c.json({ error: "not implemented" }, 501) 59); 60 61export const apiRoutes = new Hono() 62 .route("/healthz", healthRoutes) 63 .route("/forum", stubForumRoutes) 64 .route("/categories", stubCategoriesRoutes) 65 .route("/boards", stubBoardsRoutes) 66 .route("/topics", stubTopicsRoutes) 67 .route("/posts", stubPostsRoutes);