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"; | |
| 7298a17 | 12 | import settings2faRoutes from "./routes/settings-2fa"; |
| 79136bb | 13 | import issueRoutes from "./routes/issues"; |
| 14 | import repoSettings from "./routes/repo-settings"; | |
| 15 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 16 | import pullRoutes from "./routes/pulls"; |
| 17 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 18 | import forkRoutes from "./routes/fork"; |
| 19 | import webhookRoutes from "./routes/webhooks"; | |
| 20 | import exploreRoutes from "./routes/explore"; | |
| 21 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 22 | import contributorRoutes from "./routes/contributors"; |
| 3ef4c9d | 23 | import notificationRoutes from "./routes/notifications"; |
| 24 | import dashboardRoutes from "./routes/dashboard"; | |
| 25 | import askRoutes from "./routes/ask"; | |
| 26 | import releaseRoutes from "./routes/releases"; | |
| 27 | import gateRoutes from "./routes/gates"; | |
| 28 | import insightsRoutes from "./routes/insights"; | |
| 29 | import searchRoutes from "./routes/search"; | |
| 30 | import healthRoutes from "./routes/health"; | |
| ad6d4ad | 31 | import hookRoutes from "./routes/hooks"; |
| 6fc53bd | 32 | import themeRoutes from "./routes/theme"; |
| 33 | import auditRoutes from "./routes/audit"; | |
| 34 | import reactionRoutes from "./routes/reactions"; | |
| 24cf2ca | 35 | import savedReplyRoutes from "./routes/saved-replies"; |
| 36 | import deploymentRoutes from "./routes/deployments"; | |
| 6563f0a | 37 | import orgRoutes from "./routes/orgs"; |
| 2df1f8c | 38 | import passkeyRoutes from "./routes/passkeys"; |
| 058d752 | 39 | import oauthRoutes from "./routes/oauth"; |
| 40 | import developerAppsRoutes from "./routes/developer-apps"; | |
| eafe8c6 | 41 | import workflowRoutes from "./routes/workflows"; |
| 25a91a6 | 42 | import packagesApiRoutes from "./routes/packages-api"; |
| 43 | import packagesUiRoutes from "./routes/packages"; | |
| 44 | import pagesRoutes from "./routes/pages"; | |
| 45 | import environmentsRoutes from "./routes/environments"; | |
| 3cbe3d6 | 46 | import aiExplainRoutes from "./routes/ai-explain"; |
| 47 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 48 | import copilotRoutes from "./routes/copilot"; | |
| 49 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 50 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 1e162a8 | 51 | import aiTestsRoutes from "./routes/ai-tests"; |
| 52 | import discussionRoutes from "./routes/discussions"; | |
| 53 | import gistRoutes from "./routes/gists"; | |
| 54 | import projectRoutes from "./routes/projects"; | |
| 55 | import wikiRoutes from "./routes/wikis"; | |
| a79a9ed | 56 | import mergeQueueRoutes from "./routes/merge-queue"; |
| 57 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 58 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 8f50ed0 | 59 | import trafficRoutes from "./routes/traffic"; |
| 60 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 61 | import adminRoutes from "./routes/admin"; | |
| 62 | import billingRoutes from "./routes/billing"; | |
| eae38d1 | 63 | import pwaRoutes from "./routes/pwa"; |
| 64 | import graphqlRoutes from "./routes/graphql"; | |
| 06139e6 | 65 | import marketplaceRoutes from "./routes/marketplace"; |
| 71cd5ec | 66 | import templatesRoutes from "./routes/templates"; |
| 08420cd | 67 | import codeScanningRoutes from "./routes/code-scanning"; |
| 68 | import sponsorsRoutes from "./routes/sponsors"; | |
| 4c8f666 | 69 | import symbolsRoutes from "./routes/symbols"; |
| 4a0dea1 | 70 | import mirrorsRoutes from "./routes/mirrors"; |
| edf7c36 | 71 | import ssoRoutes from "./routes/sso"; |
| 8098672 | 72 | import depsRoutes from "./routes/deps"; |
| f60ccde | 73 | import advisoriesRoutes from "./routes/advisories"; |
| 3951454 | 74 | import signingKeysRoutes from "./routes/signing-keys"; |
| 7aa8b99 | 75 | import followsRoutes from "./routes/follows"; |
| 9ff7128 | 76 | import rulesetsRoutes from "./routes/rulesets"; |
| 0cdfd89 | 77 | import commitStatusesRoutes from "./routes/commit-statuses"; |
| 79136bb | 78 | import webRoutes from "./routes/web"; |
| 79 | ||
| 80 | const app = new Hono(); | |
| 81 | ||
| 3ef4c9d | 82 | // Request context (request ID, start time) runs before everything else |
| 83 | app.use("*", requestContext); | |
| 05b973e | 84 | // Middleware — compression first (wraps all responses) |
| 85 | app.use("*", compress()); | |
| 86 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 87 | app.use("*", async (c, next) => { | |
| 88 | if (c.req.path.includes(".git/")) return next(); | |
| 89 | return logger()(c, next); | |
| 90 | }); | |
| 79136bb | 91 | app.use("/api/*", cors()); |
| 3ef4c9d | 92 | // Rate-limit API + auth endpoints (generous default) |
| 93 | app.use("/api/*", rateLimit({ windowMs: 60_000, max: 120 })); | |
| 94 | app.use("/login", rateLimit({ windowMs: 60_000, max: 20 })); | |
| 95 | app.use("/register", rateLimit({ windowMs: 60_000, max: 10 })); | |
| 79136bb | 96 | |
| 97 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 98 | app.route("/", gitRoutes); | |
| 99 | ||
| 3ef4c9d | 100 | // Health + metrics |
| 101 | app.route("/", healthRoutes); | |
| 102 | ||
| ad6d4ad | 103 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 104 | app.route("/", hookRoutes); | |
| 105 | ||
| 79136bb | 106 | // REST API |
| 107 | app.route("/", apiRoutes); | |
| 108 | ||
| 109 | // Auth routes (register, login, logout) | |
| 110 | app.route("/", authRoutes); | |
| 111 | ||
| 112 | // Settings routes (profile, SSH keys) | |
| 113 | app.route("/", settingsRoutes); | |
| 114 | ||
| 7298a17 | 115 | // 2FA / TOTP settings (Block B4) |
| 116 | app.route("/", settings2faRoutes); | |
| 117 | ||
| 2df1f8c | 118 | // WebAuthn / passkey routes (Block B5) |
| 119 | app.route("/", passkeyRoutes); | |
| 120 | ||
| 058d752 | 121 | // OAuth 2.0 provider (Block B6) |
| 122 | app.route("/", oauthRoutes); | |
| 123 | app.route("/", developerAppsRoutes); | |
| 124 | ||
| 6fc53bd | 125 | // Theme toggle (dark/light cookie) |
| 126 | app.route("/", themeRoutes); | |
| 127 | ||
| 128 | // Audit log UI | |
| 129 | app.route("/", auditRoutes); | |
| 130 | ||
| 131 | // Reactions API (issues, PRs, comments) | |
| 132 | app.route("/", reactionRoutes); | |
| 133 | ||
| 24cf2ca | 134 | // Saved replies (per-user canned comment templates) |
| 135 | app.route("/", savedReplyRoutes); | |
| 136 | ||
| 137 | // Environments + deployment history UI | |
| 138 | app.route("/", deploymentRoutes); | |
| 139 | ||
| 6563f0a | 140 | // Organizations + teams (Block B1) |
| 141 | app.route("/", orgRoutes); | |
| 142 | ||
| c81ab7a | 143 | // API tokens |
| 144 | app.route("/", tokenRoutes); | |
| 145 | ||
| 3ef4c9d | 146 | // Notifications inbox |
| 147 | app.route("/", notificationRoutes); | |
| 148 | ||
| 149 | // Dashboard (/dashboard) | |
| 150 | app.route("/", dashboardRoutes); | |
| 151 | ||
| 152 | // AI assistant — /ask + /:owner/:repo/ask | |
| 153 | app.route("/", askRoutes); | |
| 154 | ||
| 155 | // Global search | |
| 156 | app.route("/", searchRoutes); | |
| 157 | ||
| 79136bb | 158 | // Repo settings (description, visibility, delete) |
| 159 | app.route("/", repoSettings); | |
| 160 | ||
| c81ab7a | 161 | // Webhooks management |
| 162 | app.route("/", webhookRoutes); | |
| 163 | ||
| 79136bb | 164 | // Compare view (branch diffs) |
| 165 | app.route("/", compareRoutes); | |
| 166 | ||
| 167 | // Issue tracker | |
| 168 | app.route("/", issueRoutes); | |
| 169 | ||
| 0074234 | 170 | // Pull requests |
| 171 | app.route("/", pullRoutes); | |
| 172 | ||
| c81ab7a | 173 | // Fork |
| 174 | app.route("/", forkRoutes); | |
| 175 | ||
| 0074234 | 176 | // Web file editor |
| 177 | app.route("/", editorRoutes); | |
| 178 | ||
| 43de941 | 179 | // Contributors |
| 180 | app.route("/", contributorRoutes); | |
| 181 | ||
| 3ef4c9d | 182 | // Releases |
| 183 | app.route("/", releaseRoutes); | |
| 184 | ||
| 185 | // Gates (history + settings + branch protection) | |
| 186 | app.route("/", gateRoutes); | |
| 187 | ||
| eafe8c6 | 188 | // Actions-equivalent workflow runner (Block C1) |
| 189 | app.route("/", workflowRoutes); | |
| 190 | ||
| 25a91a6 | 191 | // Package registry — npm protocol + UI (Block C2) |
| 192 | app.route("/", packagesApiRoutes); | |
| 193 | app.route("/", packagesUiRoutes); | |
| 194 | ||
| 195 | // Pages / static hosting (Block C3) | |
| 196 | app.route("/", pagesRoutes); | |
| 197 | ||
| 198 | // Environments with protected approvals (Block C4) | |
| 199 | app.route("/", environmentsRoutes); | |
| 200 | ||
| 3cbe3d6 | 201 | // AI-native features (Block D) |
| 202 | app.route("/", aiExplainRoutes); // D6 — /:owner/:repo/explain | |
| 203 | app.route("/", aiChangelogRoutes); // D7 — /:owner/:repo/ai/changelog | |
| 204 | app.route("/", copilotRoutes); // D9 — /api/copilot/completions | |
| 205 | app.route("/", depUpdaterRoutes); // D2 — /:owner/:repo/settings/dep-updater | |
| 206 | app.route("/", semanticSearchRoutes); // D1 — /:owner/:repo/search/semantic | |
| 1e162a8 | 207 | app.route("/", aiTestsRoutes); // D8 — /:owner/:repo/ai/tests |
| 208 | app.route("/", discussionRoutes); // E2 — /:owner/:repo/discussions | |
| 209 | app.route("/", gistRoutes); // E4 — /gists, /gists/:slug, /:user/gists | |
| 210 | app.route("/", projectRoutes); // E1 — /:owner/:repo/projects | |
| 211 | app.route("/", wikiRoutes); // E3 — /:owner/:repo/wiki | |
| a79a9ed | 212 | app.route("/", mergeQueueRoutes); // E5 — /:owner/:repo/queue |
| 213 | app.route("/", requiredChecksRoutes); // E6 — /:owner/:repo/gates/protection/:id/checks | |
| 214 | app.route("/", protectedTagsRoutes); // E7 — /:owner/:repo/settings/protected-tags | |
| 8f50ed0 | 215 | app.route("/", trafficRoutes); // F1 — /:owner/:repo/traffic |
| 216 | app.route("/", orgInsightsRoutes); // F2 — /orgs/:slug/insights | |
| 217 | app.route("/", adminRoutes); // F3 — /admin | |
| 218 | app.route("/", billingRoutes); // F4 — /settings/billing + /admin/billing | |
| 3cbe3d6 | 219 | |
| eae38d1 | 220 | // PWA — manifest + service worker + icon (Block G1) |
| 221 | app.route("/", pwaRoutes); | |
| 222 | ||
| 223 | // GraphQL mirror of REST (Block G2) | |
| 224 | app.route("/", graphqlRoutes); | |
| 225 | ||
| 06139e6 | 226 | // Marketplace + app installations + bot identities (Block H1 + H2) |
| 227 | app.route("/", marketplaceRoutes); | |
| 228 | ||
| 71cd5ec | 229 | // Template repositories — POST /:owner/:repo/use-template (Block I2) |
| 230 | app.route("/", templatesRoutes); | |
| 231 | ||
| 08420cd | 232 | // Code scanning UI — /:owner/:repo/security (Block I5) |
| 233 | app.route("/", codeScanningRoutes); | |
| 234 | ||
| 235 | // Sponsors — /sponsors/:user + /settings/sponsors (Block I6) | |
| 236 | app.route("/", sponsorsRoutes); | |
| 237 | ||
| 4c8f666 | 238 | // Symbol / xref navigation — /:owner/:repo/symbols (Block I8) |
| 239 | app.route("/", symbolsRoutes); | |
| 240 | ||
| 4a0dea1 | 241 | // Repository mirroring — /:owner/:repo/settings/mirror (Block I9) |
| 242 | app.route("/", mirrorsRoutes); | |
| 243 | ||
| edf7c36 | 244 | // Enterprise SSO via OIDC — /admin/sso + /login/sso (Block I10) |
| 245 | app.route("/", ssoRoutes); | |
| 246 | ||
| 8098672 | 247 | // Dependency graph — /:owner/:repo/dependencies (Block J1) |
| 248 | app.route("/", depsRoutes); | |
| 249 | ||
| f60ccde | 250 | // Security advisories / dependabot alerts — /:owner/:repo/security/advisories (Block J2) |
| 251 | app.route("/", advisoriesRoutes); | |
| 252 | ||
| 3951454 | 253 | // Commit signature verification / signing keys — /settings/signing-keys (Block J3) |
| 254 | app.route("/", signingKeysRoutes); | |
| 255 | ||
| 7aa8b99 | 256 | // User following + personalised feed (Block J4) |
| 257 | app.route("/", followsRoutes); | |
| 258 | ||
| 9ff7128 | 259 | // Repository rulesets — /:owner/:repo/settings/rulesets (Block J6) |
| 260 | app.route("/", rulesetsRoutes); | |
| 261 | ||
| 0cdfd89 | 262 | // Commit status API — /api/v1/repos/:o/:r/statuses/:sha (Block J8) |
| 263 | app.route("/", commitStatusesRoutes); | |
| 264 | ||
| 3ef4c9d | 265 | // Insights + milestones |
| 266 | app.route("/", insightsRoutes); | |
| 267 | ||
| c81ab7a | 268 | // Explore page |
| 269 | app.route("/", exploreRoutes); | |
| 270 | ||
| 79136bb | 271 | // Web UI (catch-all, must be last) |
| 272 | app.route("/", webRoutes); | |
| 273 | ||
| 274 | // Global 404 | |
| 275 | app.notFound((c) => { | |
| 276 | return c.html( | |
| 277 | <Layout title="Not Found"> | |
| 278 | <div class="empty-state"> | |
| 279 | <h2>404</h2> | |
| 280 | <p>Page not found.</p> | |
| 281 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 282 | Go home | |
| 283 | </a> | |
| 284 | </div> | |
| 285 | </Layout>, | |
| 286 | 404 | |
| 287 | ); | |
| 288 | }); | |
| 289 | ||
| 290 | // Global error handler | |
| 291 | app.onError((err, c) => { | |
| 292 | console.error("[error]", err); | |
| 293 | return c.html( | |
| 294 | <Layout title="Error"> | |
| 295 | <div class="empty-state"> | |
| 296 | <h2>Something went wrong</h2> | |
| 297 | <p>An unexpected error occurred.</p> | |
| 298 | {process.env.NODE_ENV !== "production" && ( | |
| 299 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 300 | {err.message} | |
| 301 | </pre> | |
| 302 | )} | |
| 303 | </div> | |
| 304 | </Layout>, | |
| 305 | 500 | |
| 306 | ); | |
| 307 | }); | |
| 308 | ||
| 309 | export default app; |