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"; | |
| 45e31d0 | 10 | import apiV2Routes from "./routes/api-v2"; |
| 11 | import apiDocsRoutes from "./routes/api-docs"; | |
| 79136bb | 12 | import authRoutes from "./routes/auth"; |
| 13 | import settingsRoutes from "./routes/settings"; | |
| 7298a17 | 14 | import settings2faRoutes from "./routes/settings-2fa"; |
| 79136bb | 15 | import issueRoutes from "./routes/issues"; |
| 16 | import repoSettings from "./routes/repo-settings"; | |
| 17 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 18 | import pullRoutes from "./routes/pulls"; |
| 19 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 20 | import forkRoutes from "./routes/fork"; |
| 21 | import webhookRoutes from "./routes/webhooks"; | |
| 22 | import exploreRoutes from "./routes/explore"; | |
| 23 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 24 | import contributorRoutes from "./routes/contributors"; |
| 2c34075 | 25 | import healthRoutes from "./routes/health"; |
| 16b325c | 26 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 27 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 28 | import legalRoutes from "./routes/legal"; |
| 79136bb | 29 | import webRoutes from "./routes/web"; |
| 59b6fb2 | 30 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 31 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 32 | |
| 33 | const app = new Hono(); | |
| 34 | ||
| 3ef4c9d | 35 | // Request context (request ID, start time) runs before everything else |
| 36 | app.use("*", requestContext); | |
| 05b973e | 37 | // Middleware — compression first (wraps all responses) |
| 38 | app.use("*", compress()); | |
| 39 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 40 | app.use("*", async (c, next) => { | |
| 41 | if (c.req.path.includes(".git/")) return next(); | |
| 42 | return logger()(c, next); | |
| 43 | }); | |
| 79136bb | 44 | app.use("/api/*", cors()); |
| 3ef4c9d | 45 | // Rate-limit API + auth endpoints (generous default) |
| 46 | app.use("/api/*", rateLimit({ windowMs: 60_000, max: 120 })); | |
| 47 | app.use("/login", rateLimit({ windowMs: 60_000, max: 20 })); | |
| 48 | app.use("/register", rateLimit({ windowMs: 60_000, max: 10 })); | |
| 79136bb | 49 | |
| 59b6fb2 | 50 | // CSRF protection — set token on all requests, validate on mutations |
| 51 | app.use("*", csrfToken); | |
| 52 | app.use("*", csrfProtect); | |
| 53 | ||
| 45e31d0 | 54 | // Rate limit auth routes |
| 55 | app.use("/login", authRateLimit); | |
| 56 | app.use("/register", authRateLimit); | |
| 57 | ||
| 59b6fb2 | 58 | // Rate limit git operations |
| 59 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 60 | ||
| 61 | // Rate limit search | |
| 62 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 63 | app.use("/explore", searchRateLimit); | |
| 79136bb | 64 | |
| 65 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 66 | app.route("/", gitRoutes); | |
| 67 | ||
| 45e31d0 | 68 | // REST API v1 (legacy) |
| 79136bb | 69 | app.route("/", apiRoutes); |
| 70 | ||
| ad6d4ad | 71 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 72 | app.route("/", hookRoutes); | |
| 21f8dbd | 73 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 74 | |
| 45e31d0 | 75 | // API documentation |
| 76 | app.route("/", apiDocsRoutes); | |
| 79136bb | 77 | |
| 78 | // Auth routes (register, login, logout) | |
| 79 | app.route("/", authRoutes); | |
| 80 | ||
| 81 | // Settings routes (profile, SSH keys) | |
| 82 | app.route("/", settingsRoutes); | |
| 83 | ||
| 7298a17 | 84 | // 2FA / TOTP settings (Block B4) |
| 85 | app.route("/", settings2faRoutes); | |
| 86 | ||
| 2df1f8c | 87 | // WebAuthn / passkey routes (Block B5) |
| 88 | app.route("/", passkeyRoutes); | |
| 89 | ||
| 058d752 | 90 | // OAuth 2.0 provider (Block B6) |
| 91 | app.route("/", oauthRoutes); | |
| 92 | app.route("/", developerAppsRoutes); | |
| 93 | ||
| 6fc53bd | 94 | // Theme toggle (dark/light cookie) |
| 95 | app.route("/", themeRoutes); | |
| 96 | ||
| 97 | // Audit log UI | |
| 98 | app.route("/", auditRoutes); | |
| 99 | ||
| 100 | // Reactions API (issues, PRs, comments) | |
| 101 | app.route("/", reactionRoutes); | |
| 102 | ||
| 24cf2ca | 103 | // Saved replies (per-user canned comment templates) |
| 104 | app.route("/", savedReplyRoutes); | |
| 105 | ||
| 106 | // Environments + deployment history UI | |
| 107 | app.route("/", deploymentRoutes); | |
| 108 | ||
| 6563f0a | 109 | // Organizations + teams (Block B1) |
| 110 | app.route("/", orgRoutes); | |
| 111 | ||
| c81ab7a | 112 | // API tokens |
| 113 | app.route("/", tokenRoutes); | |
| 114 | ||
| 59b6fb2 | 115 | // Notifications |
| 3ef4c9d | 116 | app.route("/", notificationRoutes); |
| 117 | ||
| 59b6fb2 | 118 | // Organizations |
| 119 | app.route("/", orgRoutes); | |
| 3ef4c9d | 120 | |
| 79136bb | 121 | // Repo settings (description, visibility, delete) |
| 122 | app.route("/", repoSettings); | |
| 123 | ||
| c81ab7a | 124 | // Webhooks management |
| 125 | app.route("/", webhookRoutes); | |
| 126 | ||
| 79136bb | 127 | // Compare view (branch diffs) |
| 128 | app.route("/", compareRoutes); | |
| 129 | ||
| 130 | // Issue tracker | |
| 131 | app.route("/", issueRoutes); | |
| 132 | ||
| 0074234 | 133 | // Pull requests |
| 134 | app.route("/", pullRoutes); | |
| 135 | ||
| c81ab7a | 136 | // Fork |
| 137 | app.route("/", forkRoutes); | |
| 138 | ||
| 0074234 | 139 | // Web file editor |
| 140 | app.route("/", editorRoutes); | |
| 141 | ||
| 43de941 | 142 | // Contributors |
| 143 | app.route("/", contributorRoutes); | |
| 144 | ||
| 2c34075 | 145 | // Health dashboard |
| 146 | app.route("/", healthRoutes); | |
| 147 | ||
| 16b325c | 148 | // Insights (time-travel, dependencies, rollback) |
| 149 | app.route("/", insightRoutes); | |
| 150 | ||
| f1ab587 | 151 | // Command center dashboard |
| 152 | app.route("/", dashboardRoutes); | |
| 153 | ||
| 36b4cbd | 154 | // Legal pages (terms, privacy, AUP) |
| 155 | app.route("/", legalRoutes); | |
| 156 | ||
| c81ab7a | 157 | // Explore page |
| 158 | app.route("/", exploreRoutes); | |
| 159 | ||
| 59b6fb2 | 160 | // Onboarding |
| 161 | app.route("/", onboardingRoutes); | |
| 162 | ||
| 79136bb | 163 | // Web UI (catch-all, must be last) |
| 164 | app.route("/", webRoutes); | |
| 165 | ||
| 166 | // Global 404 | |
| 167 | app.notFound((c) => { | |
| 168 | return c.html( | |
| 169 | <Layout title="Not Found"> | |
| 170 | <div class="empty-state"> | |
| 171 | <h2>404</h2> | |
| 172 | <p>Page not found.</p> | |
| 173 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 174 | Go home | |
| 175 | </a> | |
| 176 | </div> | |
| 177 | </Layout>, | |
| 178 | 404 | |
| 179 | ); | |
| 180 | }); | |
| 181 | ||
| 182 | // Global error handler | |
| 183 | app.onError((err, c) => { | |
| 184 | console.error("[error]", err); | |
| 185 | return c.html( | |
| 186 | <Layout title="Error"> | |
| 187 | <div class="empty-state"> | |
| 188 | <h2>Something went wrong</h2> | |
| 189 | <p>An unexpected error occurred.</p> | |
| 190 | {process.env.NODE_ENV !== "production" && ( | |
| 191 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 192 | {err.message} | |
| 193 | </pre> | |
| 194 | )} | |
| 195 | </div> | |
| 196 | </Layout>, | |
| 197 | 500 | |
| 198 | ); | |
| 199 | }); | |
| 200 | ||
| 201 | export default app; |