| 1 | /** @jsxImportSource hono/jsx */ |
| 2 | import { Hono } from "hono"; |
| 3 | import type { Env } from "../env.js"; |
| 4 | import type { AppVars } from "../auth/principal.js"; |
| 5 | import { registerAccount } from "./account.js"; |
| 6 | import { registerAuth } from "./auth.js"; |
| 7 | import { registerActions } from "./actions.js"; |
| 8 | import { registerCode } from "./code.js"; |
| 9 | import { registerCollab } from "./collab.js"; |
| 10 | import { registerRepoSettings } from "./repo-settings.js"; |
| 11 | import { registerSeo } from "./seo.js"; |
| 12 | import { errorPage } from "./ui.js"; |
| 13 | import { registerKumoAssets } from "./kumo.js"; |
| 14 | |
| 15 | /** |
| 16 | * Server-rendered web UI. Mount at "/" after the API, Git and runner routes: |
| 17 | * it owns `/`, `/login`, `/auth/*`, `/signin/*`, `/new`, `/settings/*`, `/notifications/*`, `/invite/*`, `/-/*`, |
| 18 | * `/:owner` and `/:owner/:repo/...` (including `/:owner/:repo/raw/*`). |
| 19 | * |
| 20 | * Expects the `principal` and `dir` variables to be set by an earlier middleware. |
| 21 | * Every POST is CSRF-checked (double-submit cookie, see ./csrf.ts). |
| 22 | */ |
| 23 | export const web = new Hono<{ Bindings: Env; Variables: AppVars }>(); |
| 24 | |
| 25 | web.onError((err, c) => errorPage(c, err)); |
| 26 | |
| 27 | // Browsers and crawlers ask for these on every origin; keep them off the /:owner route. |
| 28 | registerSeo(web); |
| 29 | |
| 30 | // Order matters: fixed paths (/settings/tokens, /notifications/:id, …) must be |
| 31 | // registered before the /:owner/:repo patterns they would otherwise match. |
| 32 | registerKumoAssets(web); |
| 33 | registerAuth(web); |
| 34 | registerAccount(web); |
| 35 | registerRepoSettings(web); |
| 36 | registerActions(web); |
| 37 | registerCollab(web); |
| 38 | registerCode(web); |