Blame · Line-by-line history
app.tsx
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| 79136bb | 1 | import { Hono } from "hono"; |
| 2 | import { logger } from "hono/logger"; | |
| 3 | import { cors } from "hono/cors"; | |
| 4 | import { Layout } from "./views/layout"; | |
| 5 | import gitRoutes from "./routes/git"; | |
| 6 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 7 | import apiV2Routes from "./routes/api-v2"; |
| 8 | import apiDocsRoutes from "./routes/api-docs"; | |
| 79136bb | 9 | import authRoutes from "./routes/auth"; |
| 10 | import settingsRoutes from "./routes/settings"; | |
| 11 | import issueRoutes from "./routes/issues"; | |
| 12 | import repoSettings from "./routes/repo-settings"; | |
| 13 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 14 | import pullRoutes from "./routes/pulls"; |
| 15 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 16 | import forkRoutes from "./routes/fork"; |
| 17 | import webhookRoutes from "./routes/webhooks"; | |
| 18 | import exploreRoutes from "./routes/explore"; | |
| 19 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 20 | import contributorRoutes from "./routes/contributors"; |
| 79136bb | 21 | import webRoutes from "./routes/web"; |
| 45e31d0 | 22 | import { authRateLimit } from "./middleware/rate-limit"; |
| 79136bb | 23 | |
| 24 | const app = new Hono(); | |
| 25 | ||
| 26 | // Middleware | |
| 27 | app.use("*", logger()); | |
| 28 | app.use("/api/*", cors()); | |
| 29 | ||
| 45e31d0 | 30 | // Rate limit auth routes |
| 31 | app.use("/login", authRateLimit); | |
| 32 | app.use("/register", authRateLimit); | |
| 33 | ||
| 79136bb | 34 | // Git Smart HTTP protocol routes (must be before web routes) |
| 35 | app.route("/", gitRoutes); | |
| 36 | ||
| 45e31d0 | 37 | // REST API v1 (legacy) |
| 79136bb | 38 | app.route("/", apiRoutes); |
| 39 | ||
| 45e31d0 | 40 | // REST API v2 (comprehensive, token-authenticated) |
| 41 | app.route("/", apiV2Routes); | |
| 42 | ||
| 43 | // API documentation | |
| 44 | app.route("/", apiDocsRoutes); | |
| 45 | ||
| 79136bb | 46 | // Auth routes (register, login, logout) |
| 47 | app.route("/", authRoutes); | |
| 48 | ||
| 49 | // Settings routes (profile, SSH keys) | |
| 50 | app.route("/", settingsRoutes); | |
| 51 | ||
| c81ab7a | 52 | // API tokens |
| 53 | app.route("/", tokenRoutes); | |
| 54 | ||
| 79136bb | 55 | // Repo settings (description, visibility, delete) |
| 56 | app.route("/", repoSettings); | |
| 57 | ||
| c81ab7a | 58 | // Webhooks management |
| 59 | app.route("/", webhookRoutes); | |
| 60 | ||
| 79136bb | 61 | // Compare view (branch diffs) |
| 62 | app.route("/", compareRoutes); | |
| 63 | ||
| 64 | // Issue tracker | |
| 65 | app.route("/", issueRoutes); | |
| 66 | ||
| 0074234 | 67 | // Pull requests |
| 68 | app.route("/", pullRoutes); | |
| 69 | ||
| c81ab7a | 70 | // Fork |
| 71 | app.route("/", forkRoutes); | |
| 72 | ||
| 0074234 | 73 | // Web file editor |
| 74 | app.route("/", editorRoutes); | |
| 75 | ||
| 43de941 | 76 | // Contributors |
| 77 | app.route("/", contributorRoutes); | |
| 78 | ||
| c81ab7a | 79 | // Explore page |
| 80 | app.route("/", exploreRoutes); | |
| 81 | ||
| 79136bb | 82 | // Web UI (catch-all, must be last) |
| 83 | app.route("/", webRoutes); | |
| 84 | ||
| 85 | // Global 404 | |
| 86 | app.notFound((c) => { | |
| 87 | return c.html( | |
| 88 | <Layout title="Not Found"> | |
| 89 | <div class="empty-state"> | |
| 90 | <h2>404</h2> | |
| 91 | <p>Page not found.</p> | |
| 92 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 93 | Go home | |
| 94 | </a> | |
| 95 | </div> | |
| 96 | </Layout>, | |
| 97 | 404 | |
| 98 | ); | |
| 99 | }); | |
| 100 | ||
| 101 | // Global error handler | |
| 102 | app.onError((err, c) => { | |
| 103 | console.error("[error]", err); | |
| 104 | return c.html( | |
| 105 | <Layout title="Error"> | |
| 106 | <div class="empty-state"> | |
| 107 | <h2>Something went wrong</h2> | |
| 108 | <p>An unexpected error occurred.</p> | |
| 109 | {process.env.NODE_ENV !== "production" && ( | |
| 110 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 111 | {err.message} | |
| 112 | </pre> | |
| 113 | )} | |
| 114 | </div> | |
| 115 | </Layout>, | |
| 116 | 500 | |
| 117 | ); | |
| 118 | }); | |
| 119 | ||
| 120 | export default app; |