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"; | |
| 05b973e | 4 | import { compress } from "hono/compress"; |
| 79136bb | 5 | import { Layout } from "./views/layout"; |
| 3ef4c9d | 6 | import { requestContext } from "./middleware/request-context"; |
| 7 | import { rateLimit } from "./middleware/rate-limit"; | |
| 79136bb | 8 | import gitRoutes from "./routes/git"; |
| 9 | import apiRoutes from "./routes/api"; | |
| 10 | import authRoutes from "./routes/auth"; | |
| 11 | import settingsRoutes from "./routes/settings"; | |
| 12 | import issueRoutes from "./routes/issues"; | |
| 13 | import repoSettings from "./routes/repo-settings"; | |
| 14 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 15 | import pullRoutes from "./routes/pulls"; |
| 16 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 17 | import forkRoutes from "./routes/fork"; |
| 18 | import webhookRoutes from "./routes/webhooks"; | |
| 19 | import exploreRoutes from "./routes/explore"; | |
| 20 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 21 | import contributorRoutes from "./routes/contributors"; |
| 3ef4c9d | 22 | import notificationRoutes from "./routes/notifications"; |
| 23 | import dashboardRoutes from "./routes/dashboard"; | |
| 24 | import askRoutes from "./routes/ask"; | |
| 25 | import releaseRoutes from "./routes/releases"; | |
| 26 | import gateRoutes from "./routes/gates"; | |
| 27 | import insightsRoutes from "./routes/insights"; | |
| 28 | import searchRoutes from "./routes/search"; | |
| 29 | import healthRoutes from "./routes/health"; | |
| 79136bb | 30 | import webRoutes from "./routes/web"; |
| 31 | ||
| 32 | const app = new Hono(); | |
| 33 | ||
| 3ef4c9d | 34 | // Request context (request ID, start time) runs before everything else |
| 35 | app.use("*", requestContext); | |
| 05b973e | 36 | // Middleware — compression first (wraps all responses) |
| 37 | app.use("*", compress()); | |
| 38 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 39 | app.use("*", async (c, next) => { | |
| 40 | if (c.req.path.includes(".git/")) return next(); | |
| 41 | return logger()(c, next); | |
| 42 | }); | |
| 79136bb | 43 | app.use("/api/*", cors()); |
| 3ef4c9d | 44 | // Rate-limit API + auth endpoints (generous default) |
| 45 | app.use("/api/*", rateLimit({ windowMs: 60_000, max: 120 })); | |
| 46 | app.use("/login", rateLimit({ windowMs: 60_000, max: 20 })); | |
| 47 | app.use("/register", rateLimit({ windowMs: 60_000, max: 10 })); | |
| 79136bb | 48 | |
| 49 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 50 | app.route("/", gitRoutes); | |
| 51 | ||
| 3ef4c9d | 52 | // Health + metrics |
| 53 | app.route("/", healthRoutes); | |
| 54 | ||
| 79136bb | 55 | // REST API |
| 56 | app.route("/", apiRoutes); | |
| 57 | ||
| 58 | // Auth routes (register, login, logout) | |
| 59 | app.route("/", authRoutes); | |
| 60 | ||
| 61 | // Settings routes (profile, SSH keys) | |
| 62 | app.route("/", settingsRoutes); | |
| 63 | ||
| c81ab7a | 64 | // API tokens |
| 65 | app.route("/", tokenRoutes); | |
| 66 | ||
| 3ef4c9d | 67 | // Notifications inbox |
| 68 | app.route("/", notificationRoutes); | |
| 69 | ||
| 70 | // Dashboard (/dashboard) | |
| 71 | app.route("/", dashboardRoutes); | |
| 72 | ||
| 73 | // AI assistant — /ask + /:owner/:repo/ask | |
| 74 | app.route("/", askRoutes); | |
| 75 | ||
| 76 | // Global search | |
| 77 | app.route("/", searchRoutes); | |
| 78 | ||
| 79136bb | 79 | // Repo settings (description, visibility, delete) |
| 80 | app.route("/", repoSettings); | |
| 81 | ||
| c81ab7a | 82 | // Webhooks management |
| 83 | app.route("/", webhookRoutes); | |
| 84 | ||
| 79136bb | 85 | // Compare view (branch diffs) |
| 86 | app.route("/", compareRoutes); | |
| 87 | ||
| 88 | // Issue tracker | |
| 89 | app.route("/", issueRoutes); | |
| 90 | ||
| 0074234 | 91 | // Pull requests |
| 92 | app.route("/", pullRoutes); | |
| 93 | ||
| c81ab7a | 94 | // Fork |
| 95 | app.route("/", forkRoutes); | |
| 96 | ||
| 0074234 | 97 | // Web file editor |
| 98 | app.route("/", editorRoutes); | |
| 99 | ||
| 43de941 | 100 | // Contributors |
| 101 | app.route("/", contributorRoutes); | |
| 102 | ||
| 3ef4c9d | 103 | // Releases |
| 104 | app.route("/", releaseRoutes); | |
| 105 | ||
| 106 | // Gates (history + settings + branch protection) | |
| 107 | app.route("/", gateRoutes); | |
| 108 | ||
| 109 | // Insights + milestones | |
| 110 | app.route("/", insightsRoutes); | |
| 111 | ||
| c81ab7a | 112 | // Explore page |
| 113 | app.route("/", exploreRoutes); | |
| 114 | ||
| 79136bb | 115 | // Web UI (catch-all, must be last) |
| 116 | app.route("/", webRoutes); | |
| 117 | ||
| 118 | // Global 404 | |
| 119 | app.notFound((c) => { | |
| 120 | return c.html( | |
| 121 | <Layout title="Not Found"> | |
| 122 | <div class="empty-state"> | |
| 123 | <h2>404</h2> | |
| 124 | <p>Page not found.</p> | |
| 125 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 126 | Go home | |
| 127 | </a> | |
| 128 | </div> | |
| 129 | </Layout>, | |
| 130 | 404 | |
| 131 | ); | |
| 132 | }); | |
| 133 | ||
| 134 | // Global error handler | |
| 135 | app.onError((err, c) => { | |
| 136 | console.error("[error]", err); | |
| 137 | return c.html( | |
| 138 | <Layout title="Error"> | |
| 139 | <div class="empty-state"> | |
| 140 | <h2>Something went wrong</h2> | |
| 141 | <p>An unexpected error occurred.</p> | |
| 142 | {process.env.NODE_ENV !== "production" && ( | |
| 143 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 144 | {err.message} | |
| 145 | </pre> | |
| 146 | )} | |
| 147 | </div> | |
| 148 | </Layout>, | |
| 149 | 500 | |
| 150 | ); | |
| 151 | }); | |
| 152 | ||
| 153 | export default app; |