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"; |
| 59b6fb2 | 25 | import notificationRoutes from "./routes/notifications"; |
| 26 | import orgRoutes from "./routes/orgs"; | |
| 27 | import onboardingRoutes from "./routes/onboarding"; | |
| 79136bb | 28 | import webRoutes from "./routes/web"; |
| 59b6fb2 | 29 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 30 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 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 | |
| 59b6fb2 | 49 | // CSRF protection — set token on all requests, validate on mutations |
| 50 | app.use("*", csrfToken); | |
| 51 | app.use("*", csrfProtect); | |
| 52 | ||
| 45e31d0 | 53 | // Rate limit auth routes |
| 54 | app.use("/login", authRateLimit); | |
| 55 | app.use("/register", authRateLimit); | |
| 56 | ||
| 59b6fb2 | 57 | // Rate limit git operations |
| 58 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 59 | ||
| 60 | // Rate limit search | |
| 61 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 62 | app.use("/explore", searchRateLimit); | |
| 63 | ||
| 79136bb | 64 | // Git Smart HTTP protocol routes (must be before web routes) |
| 65 | app.route("/", gitRoutes); | |
| 66 | ||
| 45e31d0 | 67 | // REST API v1 (legacy) |
| 79136bb | 68 | app.route("/", apiRoutes); |
| 69 | ||
| 45e31d0 | 70 | // REST API v2 (comprehensive, token-authenticated) |
| 71 | app.route("/", apiV2Routes); | |
| 72 | ||
| 73 | // API documentation | |
| 74 | app.route("/", apiDocsRoutes); | |
| 75 | ||
| 79136bb | 76 | // Auth routes (register, login, logout) |
| 77 | app.route("/", authRoutes); | |
| 78 | ||
| 79 | // Settings routes (profile, SSH keys) | |
| 80 | app.route("/", settingsRoutes); | |
| 81 | ||
| 7298a17 | 82 | // 2FA / TOTP settings (Block B4) |
| 83 | app.route("/", settings2faRoutes); | |
| 84 | ||
| 2df1f8c | 85 | // WebAuthn / passkey routes (Block B5) |
| 86 | app.route("/", passkeyRoutes); | |
| 87 | ||
| 058d752 | 88 | // OAuth 2.0 provider (Block B6) |
| 89 | app.route("/", oauthRoutes); | |
| 90 | app.route("/", developerAppsRoutes); | |
| 91 | ||
| 6fc53bd | 92 | // Theme toggle (dark/light cookie) |
| 93 | app.route("/", themeRoutes); | |
| 94 | ||
| 95 | // Audit log UI | |
| 96 | app.route("/", auditRoutes); | |
| 97 | ||
| 98 | // Reactions API (issues, PRs, comments) | |
| 99 | app.route("/", reactionRoutes); | |
| 100 | ||
| 24cf2ca | 101 | // Saved replies (per-user canned comment templates) |
| 102 | app.route("/", savedReplyRoutes); | |
| 103 | ||
| 104 | // Environments + deployment history UI | |
| 105 | app.route("/", deploymentRoutes); | |
| 106 | ||
| 6563f0a | 107 | // Organizations + teams (Block B1) |
| 108 | app.route("/", orgRoutes); | |
| 109 | ||
| c81ab7a | 110 | // API tokens |
| 111 | app.route("/", tokenRoutes); | |
| 112 | ||
| 59b6fb2 | 113 | // Notifications |
| 114 | app.route("/", notificationRoutes); | |
| 115 | ||
| 116 | // Organizations | |
| 117 | app.route("/", orgRoutes); | |
| 118 | ||
| 79136bb | 119 | // Repo settings (description, visibility, delete) |
| 120 | app.route("/", repoSettings); | |
| 121 | ||
| c81ab7a | 122 | // Webhooks management |
| 123 | app.route("/", webhookRoutes); | |
| 124 | ||
| 79136bb | 125 | // Compare view (branch diffs) |
| 126 | app.route("/", compareRoutes); | |
| 127 | ||
| 128 | // Issue tracker | |
| 129 | app.route("/", issueRoutes); | |
| 130 | ||
| 0074234 | 131 | // Pull requests |
| 132 | app.route("/", pullRoutes); | |
| 133 | ||
| c81ab7a | 134 | // Fork |
| 135 | app.route("/", forkRoutes); | |
| 136 | ||
| 0074234 | 137 | // Web file editor |
| 138 | app.route("/", editorRoutes); | |
| 139 | ||
| 43de941 | 140 | // Contributors |
| 141 | app.route("/", contributorRoutes); | |
| 142 | ||
| 3ef4c9d | 143 | // Releases |
| 144 | app.route("/", releaseRoutes); | |
| 145 | ||
| 146 | // Gates (history + settings + branch protection) | |
| 147 | app.route("/", gateRoutes); | |
| 148 | ||
| eafe8c6 | 149 | // Actions-equivalent workflow runner (Block C1) |
| 150 | app.route("/", workflowRoutes); | |
| 151 | ||
| 25a91a6 | 152 | // Package registry — npm protocol + UI (Block C2) |
| 153 | app.route("/", packagesApiRoutes); | |
| 154 | app.route("/", packagesUiRoutes); | |
| 155 | ||
| 156 | // Pages / static hosting (Block C3) | |
| 157 | app.route("/", pagesRoutes); | |
| 158 | ||
| 159 | // Environments with protected approvals (Block C4) | |
| 160 | app.route("/", environmentsRoutes); | |
| 161 | ||
| 3cbe3d6 | 162 | // AI-native features (Block D) |
| 163 | app.route("/", aiExplainRoutes); // D6 — /:owner/:repo/explain | |
| 164 | app.route("/", aiChangelogRoutes); // D7 — /:owner/:repo/ai/changelog | |
| 165 | app.route("/", copilotRoutes); // D9 — /api/copilot/completions | |
| 166 | app.route("/", depUpdaterRoutes); // D2 — /:owner/:repo/settings/dep-updater | |
| 167 | app.route("/", semanticSearchRoutes); // D1 — /:owner/:repo/search/semantic | |
| 1e162a8 | 168 | app.route("/", aiTestsRoutes); // D8 — /:owner/:repo/ai/tests |
| 169 | app.route("/", discussionRoutes); // E2 — /:owner/:repo/discussions | |
| 170 | app.route("/", gistRoutes); // E4 — /gists, /gists/:slug, /:user/gists | |
| 171 | app.route("/", projectRoutes); // E1 — /:owner/:repo/projects | |
| 172 | app.route("/", wikiRoutes); // E3 — /:owner/:repo/wiki | |
| a79a9ed | 173 | app.route("/", mergeQueueRoutes); // E5 — /:owner/:repo/queue |
| 174 | app.route("/", requiredChecksRoutes); // E6 — /:owner/:repo/gates/protection/:id/checks | |
| 175 | app.route("/", protectedTagsRoutes); // E7 — /:owner/:repo/settings/protected-tags | |
| 8f50ed0 | 176 | app.route("/", trafficRoutes); // F1 — /:owner/:repo/traffic |
| 177 | app.route("/", orgInsightsRoutes); // F2 — /orgs/:slug/insights | |
| 178 | app.route("/", adminRoutes); // F3 — /admin | |
| 179 | app.route("/", billingRoutes); // F4 — /settings/billing + /admin/billing | |
| 3cbe3d6 | 180 | |
| eae38d1 | 181 | // PWA — manifest + service worker + icon (Block G1) |
| 182 | app.route("/", pwaRoutes); | |
| 183 | ||
| 184 | // GraphQL mirror of REST (Block G2) | |
| 185 | app.route("/", graphqlRoutes); | |
| 186 | ||
| 06139e6 | 187 | // Marketplace + app installations + bot identities (Block H1 + H2) |
| 188 | app.route("/", marketplaceRoutes); | |
| 189 | ||
| 71cd5ec | 190 | // Template repositories — POST /:owner/:repo/use-template (Block I2) |
| 191 | app.route("/", templatesRoutes); | |
| 192 | ||
| 08420cd | 193 | // Code scanning UI — /:owner/:repo/security (Block I5) |
| 194 | app.route("/", codeScanningRoutes); | |
| 195 | ||
| 196 | // Sponsors — /sponsors/:user + /settings/sponsors (Block I6) | |
| 197 | app.route("/", sponsorsRoutes); | |
| 198 | ||
| 4c8f666 | 199 | // Symbol / xref navigation — /:owner/:repo/symbols (Block I8) |
| 200 | app.route("/", symbolsRoutes); | |
| 201 | ||
| 4a0dea1 | 202 | // Repository mirroring — /:owner/:repo/settings/mirror (Block I9) |
| 203 | app.route("/", mirrorsRoutes); | |
| 204 | ||
| edf7c36 | 205 | // Enterprise SSO via OIDC — /admin/sso + /login/sso (Block I10) |
| 206 | app.route("/", ssoRoutes); | |
| 207 | ||
| 8098672 | 208 | // Dependency graph — /:owner/:repo/dependencies (Block J1) |
| 209 | app.route("/", depsRoutes); | |
| 210 | ||
| f60ccde | 211 | // Security advisories / dependabot alerts — /:owner/:repo/security/advisories (Block J2) |
| 212 | app.route("/", advisoriesRoutes); | |
| 213 | ||
| 3951454 | 214 | // Commit signature verification / signing keys — /settings/signing-keys (Block J3) |
| 215 | app.route("/", signingKeysRoutes); | |
| 216 | ||
| 7aa8b99 | 217 | // User following + personalised feed (Block J4) |
| 218 | app.route("/", followsRoutes); | |
| 219 | ||
| 9ff7128 | 220 | // Repository rulesets — /:owner/:repo/settings/rulesets (Block J6) |
| 221 | app.route("/", rulesetsRoutes); | |
| 222 | ||
| 0cdfd89 | 223 | // Commit status API — /api/v1/repos/:o/:r/statuses/:sha (Block J8) |
| 224 | app.route("/", commitStatusesRoutes); | |
| 225 | ||
| 3ef4c9d | 226 | // Insights + milestones |
| 227 | app.route("/", insightsRoutes); | |
| 228 | ||
| c81ab7a | 229 | // Explore page |
| 230 | app.route("/", exploreRoutes); | |
| 231 | ||
| 59b6fb2 | 232 | // Onboarding |
| 233 | app.route("/", onboardingRoutes); | |
| 234 | ||
| 79136bb | 235 | // Web UI (catch-all, must be last) |
| 236 | app.route("/", webRoutes); | |
| 237 | ||
| 238 | // Global 404 | |
| 239 | app.notFound((c) => { | |
| 240 | return c.html( | |
| 241 | <Layout title="Not Found"> | |
| 242 | <div class="empty-state"> | |
| 243 | <h2>404</h2> | |
| 244 | <p>Page not found.</p> | |
| 245 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 246 | Go home | |
| 247 | </a> | |
| 248 | </div> | |
| 249 | </Layout>, | |
| 250 | 404 | |
| 251 | ); | |
| 252 | }); | |
| 253 | ||
| 254 | // Global error handler | |
| 255 | app.onError((err, c) => { | |
| 256 | console.error("[error]", err); | |
| 257 | return c.html( | |
| 258 | <Layout title="Error"> | |
| 259 | <div class="empty-state"> | |
| 260 | <h2>Something went wrong</h2> | |
| 261 | <p>An unexpected error occurred.</p> | |
| 262 | {process.env.NODE_ENV !== "production" && ( | |
| 263 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 264 | {err.message} | |
| 265 | </pre> | |
| 266 | )} | |
| 267 | </div> | |
| 268 | </Layout>, | |
| 269 | 500 | |
| 270 | ); | |
| 271 | }); | |
| 272 | ||
| 273 | export default app; |