CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
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"; |
| 80bed05 | 6 | import { reportError } from "./lib/observability"; |
| 3ef4c9d | 7 | import { requestContext } from "./middleware/request-context"; |
| 8 | import { rateLimit } from "./middleware/rate-limit"; | |
| 79136bb | 9 | import gitRoutes from "./routes/git"; |
| 10 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 11 | import apiV2Routes from "./routes/api-v2"; |
| 12 | import apiDocsRoutes from "./routes/api-docs"; | |
| 79136bb | 13 | import authRoutes from "./routes/auth"; |
| 14 | import settingsRoutes from "./routes/settings"; | |
| 7298a17 | 15 | import settings2faRoutes from "./routes/settings-2fa"; |
| 79136bb | 16 | import issueRoutes from "./routes/issues"; |
| 17 | import repoSettings from "./routes/repo-settings"; | |
| 23d1a81 | 18 | import collaboratorRoutes from "./routes/collaborators"; |
| 04f6b7f | 19 | import teamCollaboratorRoutes from "./routes/team-collaborators"; |
| 20 | import invitesRoutes from "./routes/invites"; | |
| 21 | import liveEventsRoutes from "./routes/live-events"; | |
| 79136bb | 22 | import compareRoutes from "./routes/compare"; |
| 0074234 | 23 | import pullRoutes from "./routes/pulls"; |
| 24 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 25 | import forkRoutes from "./routes/fork"; |
| 26 | import webhookRoutes from "./routes/webhooks"; | |
| 27 | import exploreRoutes from "./routes/explore"; | |
| 28 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 29 | import contributorRoutes from "./routes/contributors"; |
| 699e5c7 | 30 | import healthRoutes from "./routes/health-probe"; |
| 31 | import healthDashboardRoutes from "./routes/health"; | |
| 2316be6 | 32 | import statusRoutes from "./routes/status"; |
| 80bed05 | 33 | import helpRoutes from "./routes/help"; |
| 5618f9a | 34 | import seoRoutes from "./routes/seo"; |
| f295f78 | 35 | import { platformStatus } from "./routes/platform-status"; |
| 16b325c | 36 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 37 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 38 | import legalRoutes from "./routes/legal"; |
| bdbd0de | 39 | import importRoutes from "./routes/import"; |
| 14c3cc8 | 40 | import importBulkRoutes from "./routes/import-bulk"; |
| 41 | import migrationRoutes from "./routes/migrations"; | |
| 42 | import specsRoutes from "./routes/specs"; | |
| 79136bb | 43 | import webRoutes from "./routes/web"; |
| 0316dbb | 44 | import hookRoutes from "./routes/hooks"; |
| 45 | import eventsRoutes from "./routes/events"; | |
| 46 | import passkeyRoutes from "./routes/passkeys"; | |
| 47 | import oauthRoutes from "./routes/oauth"; | |
| 48 | import developerAppsRoutes from "./routes/developer-apps"; | |
| 49 | import themeRoutes from "./routes/theme"; | |
| 50 | import auditRoutes from "./routes/audit"; | |
| 51 | import reactionRoutes from "./routes/reactions"; | |
| 52 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 53 | import deploymentRoutes from "./routes/deployments"; | |
| 54 | import orgRoutes from "./routes/orgs"; | |
| 55 | import notificationRoutes from "./routes/notifications"; | |
| 56 | import onboardingRoutes from "./routes/onboarding"; | |
| 57 | import adminRoutes from "./routes/admin"; | |
| 58 | import advisoriesRoutes from "./routes/advisories"; | |
| 59 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 60 | import aiExplainRoutes from "./routes/ai-explain"; | |
| 61 | import aiTestsRoutes from "./routes/ai-tests"; | |
| 62 | import askRoutes from "./routes/ask"; | |
| 63 | import billingRoutes from "./routes/billing"; | |
| 6778ad2 | 64 | import stripeWebhookRoutes from "./routes/stripe-webhook"; |
| 0316dbb | 65 | import codeScanningRoutes from "./routes/code-scanning"; |
| 66 | import commitStatusesRoutes from "./routes/commit-statuses"; | |
| 67 | import copilotRoutes from "./routes/copilot"; | |
| 68 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 69 | import depsRoutes from "./routes/deps"; | |
| 70 | import discussionsRoutes from "./routes/discussions"; | |
| 71 | import environmentsRoutes from "./routes/environments"; | |
| 72 | import followsRoutes from "./routes/follows"; | |
| 73 | import gatesRoutes from "./routes/gates"; | |
| 74 | import gistsRoutes from "./routes/gists"; | |
| 75 | import graphqlRoutes from "./routes/graphql"; | |
| 76 | import marketplaceRoutes from "./routes/marketplace"; | |
| 77 | import mergeQueueRoutes from "./routes/merge-queue"; | |
| 78 | import mirrorsRoutes from "./routes/mirrors"; | |
| 79 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 80 | import packagesRoutes from "./routes/packages"; | |
| 81 | import packagesApiRoutes from "./routes/packages-api"; | |
| 82 | import pagesRoutes from "./routes/pages"; | |
| 83 | import projectsRoutes from "./routes/projects"; | |
| 84 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 85 | import pwaRoutes from "./routes/pwa"; | |
| 86 | import releasesRoutes from "./routes/releases"; | |
| 87 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 88 | import rulesetsRoutes from "./routes/rulesets"; | |
| 89 | import searchRoutes from "./routes/search"; | |
| 90 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 91 | import signingKeysRoutes from "./routes/signing-keys"; | |
| 92 | import sponsorsRoutes from "./routes/sponsors"; | |
| 93 | import ssoRoutes from "./routes/sso"; | |
| 94 | import symbolsRoutes from "./routes/symbols"; | |
| 95 | import templatesRoutes from "./routes/templates"; | |
| 96 | import trafficRoutes from "./routes/traffic"; | |
| 97 | import wikisRoutes from "./routes/wikis"; | |
| 98 | import workflowsRoutes from "./routes/workflows"; | |
| 5ff9cc2 | 99 | import workflowArtifactsRoutes from "./routes/workflow-artifacts"; |
| 100 | import workflowSecretsRoutes from "./routes/workflow-secrets"; | |
| 59b6fb2 | 101 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 102 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 103 | |
| 104 | const app = new Hono(); | |
| 105 | ||
| 3ef4c9d | 106 | // Request context (request ID, start time) runs before everything else |
| 107 | app.use("*", requestContext); | |
| 05b973e | 108 | // Middleware — compression first (wraps all responses) |
| 109 | app.use("*", compress()); | |
| 110 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 111 | app.use("*", async (c, next) => { | |
| 112 | if (c.req.path.includes(".git/")) return next(); | |
| 113 | return logger()(c, next); | |
| 114 | }); | |
| 79136bb | 115 | app.use("/api/*", cors()); |
| 3ef4c9d | 116 | // Rate-limit API + auth endpoints (generous default) |
| 0316dbb | 117 | app.use("/api/*", rateLimit(120, 60_000, "api")); |
| 118 | app.use("/login", rateLimit(20, 60_000, "login")); | |
| 119 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| 79136bb | 120 | |
| 59b6fb2 | 121 | // CSRF protection — set token on all requests, validate on mutations |
| 122 | app.use("*", csrfToken); | |
| 123 | app.use("*", csrfProtect); | |
| 124 | ||
| 45e31d0 | 125 | // Rate limit auth routes |
| 126 | app.use("/login", authRateLimit); | |
| 127 | app.use("/register", authRateLimit); | |
| 128 | ||
| 59b6fb2 | 129 | // Rate limit git operations |
| 130 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 131 | ||
| 132 | // Rate limit search | |
| 133 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 134 | app.use("/explore", searchRateLimit); | |
| 79136bb | 135 | |
| 136 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 137 | app.route("/", gitRoutes); | |
| 138 | ||
| 45e31d0 | 139 | // REST API v1 (legacy) |
| 79136bb | 140 | app.route("/", apiRoutes); |
| 141 | ||
| 0316dbb | 142 | // REST API v2 (basePath /api/v2) |
| 143 | app.route("/", apiV2Routes); | |
| 144 | ||
| ad6d4ad | 145 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 146 | app.route("/", hookRoutes); | |
| 21f8dbd | 147 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 148 | |
| 45e31d0 | 149 | // API documentation |
| 150 | app.route("/", apiDocsRoutes); | |
| 79136bb | 151 | |
| 152 | // Auth routes (register, login, logout) | |
| 153 | app.route("/", authRoutes); | |
| 154 | ||
| 155 | // Settings routes (profile, SSH keys) | |
| 156 | app.route("/", settingsRoutes); | |
| 157 | ||
| 7298a17 | 158 | // 2FA / TOTP settings (Block B4) |
| 159 | app.route("/", settings2faRoutes); | |
| 160 | ||
| 2df1f8c | 161 | // WebAuthn / passkey routes (Block B5) |
| 162 | app.route("/", passkeyRoutes); | |
| 163 | ||
| 058d752 | 164 | // OAuth 2.0 provider (Block B6) |
| 165 | app.route("/", oauthRoutes); | |
| 166 | app.route("/", developerAppsRoutes); | |
| 167 | ||
| 6fc53bd | 168 | // Theme toggle (dark/light cookie) |
| 169 | app.route("/", themeRoutes); | |
| 170 | ||
| 171 | // Audit log UI | |
| 172 | app.route("/", auditRoutes); | |
| 173 | ||
| 174 | // Reactions API (issues, PRs, comments) | |
| 175 | app.route("/", reactionRoutes); | |
| 176 | ||
| 24cf2ca | 177 | // Saved replies (per-user canned comment templates) |
| 178 | app.route("/", savedReplyRoutes); | |
| 179 | ||
| 180 | // Environments + deployment history UI | |
| 181 | app.route("/", deploymentRoutes); | |
| 182 | ||
| 6563f0a | 183 | // Organizations + teams (Block B1) |
| 184 | app.route("/", orgRoutes); | |
| 185 | ||
| c81ab7a | 186 | // API tokens |
| 187 | app.route("/", tokenRoutes); | |
| 188 | ||
| 59b6fb2 | 189 | // Notifications |
| 3ef4c9d | 190 | app.route("/", notificationRoutes); |
| 191 | ||
| 79136bb | 192 | // Repo settings (description, visibility, delete) |
| 193 | app.route("/", repoSettings); | |
| 194 | ||
| 23d1a81 | 195 | // Repo collaborators (add/list/remove) |
| 196 | app.route("/", collaboratorRoutes); | |
| 197 | ||
| 04f6b7f | 198 | // Team-based repo collaborators (invite a whole team) |
| 199 | app.route("/", teamCollaboratorRoutes); | |
| 200 | ||
| 201 | // Collaborator invite accept flow (token-based) | |
| 202 | app.route("/", invitesRoutes); | |
| 203 | ||
| 204 | // Real-time SSE endpoint (topic-based live updates) | |
| 205 | app.route("/", liveEventsRoutes); | |
| 206 | ||
| c81ab7a | 207 | // Webhooks management |
| 208 | app.route("/", webhookRoutes); | |
| 209 | ||
| 79136bb | 210 | // Compare view (branch diffs) |
| 211 | app.route("/", compareRoutes); | |
| 212 | ||
| 213 | // Issue tracker | |
| 214 | app.route("/", issueRoutes); | |
| 215 | ||
| 0074234 | 216 | // Pull requests |
| 217 | app.route("/", pullRoutes); | |
| 218 | ||
| c81ab7a | 219 | // Fork |
| 220 | app.route("/", forkRoutes); | |
| 221 | ||
| 0074234 | 222 | // Web file editor |
| 223 | app.route("/", editorRoutes); | |
| 224 | ||
| 43de941 | 225 | // Contributors |
| 226 | app.route("/", contributorRoutes); | |
| 227 | ||
| 699e5c7 | 228 | // Health liveness + metrics endpoints |
| 2c34075 | 229 | app.route("/", healthRoutes); |
| 230 | ||
| f295f78 | 231 | // Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md) |
| 232 | app.route("/api/platform-status", platformStatus); | |
| 233 | ||
| 2316be6 | 234 | // Public /status — human-readable platform health page |
| 235 | app.route("/", statusRoutes); | |
| 236 | ||
| 80bed05 | 237 | // /help — quickstart + API cheatsheet |
| 238 | app.route("/", helpRoutes); | |
| 239 | ||
| 5618f9a | 240 | // SEO: robots.txt + sitemap.xml |
| 241 | app.route("/", seoRoutes); | |
| 242 | ||
| 699e5c7 | 243 | // Health dashboard (per-repo health page) |
| 244 | app.route("/", healthDashboardRoutes); | |
| 245 | ||
| 16b325c | 246 | // Insights (time-travel, dependencies, rollback) |
| 247 | app.route("/", insightRoutes); | |
| 248 | ||
| f1ab587 | 249 | // Command center dashboard |
| 250 | app.route("/", dashboardRoutes); | |
| 251 | ||
| 36b4cbd | 252 | // Legal pages (terms, privacy, AUP) |
| 253 | app.route("/", legalRoutes); | |
| 254 | ||
| bdbd0de | 255 | // GitHub import / migration |
| 256 | app.route("/", importRoutes); | |
| 14c3cc8 | 257 | app.route("/", importBulkRoutes); |
| 258 | app.route("/", migrationRoutes); | |
| 259 | ||
| 260 | // Spec-to-PR (experimental AI-generated draft PRs) | |
| 261 | app.route("/", specsRoutes); | |
| bdbd0de | 262 | |
| c81ab7a | 263 | // Explore page |
| 264 | app.route("/", exploreRoutes); | |
| 265 | ||
| 59b6fb2 | 266 | // Onboarding |
| 267 | app.route("/", onboardingRoutes); | |
| 268 | ||
| 0316dbb | 269 | // Admin + feature routes |
| 270 | app.route("/", adminRoutes); | |
| 271 | app.route("/", advisoriesRoutes); | |
| 272 | app.route("/", aiChangelogRoutes); | |
| 273 | app.route("/", aiExplainRoutes); | |
| 274 | app.route("/", aiTestsRoutes); | |
| 275 | app.route("/", askRoutes); | |
| 276 | app.route("/", billingRoutes); | |
| 6778ad2 | 277 | app.route("/", stripeWebhookRoutes); |
| 0316dbb | 278 | app.route("/", codeScanningRoutes); |
| 279 | app.route("/", commitStatusesRoutes); | |
| 280 | app.route("/", copilotRoutes); | |
| 281 | app.route("/", depUpdaterRoutes); | |
| 282 | app.route("/", depsRoutes); | |
| 283 | app.route("/", discussionsRoutes); | |
| 284 | app.route("/", environmentsRoutes); | |
| 285 | app.route("/", followsRoutes); | |
| 286 | app.route("/", gatesRoutes); | |
| 287 | app.route("/", gistsRoutes); | |
| 288 | app.route("/", graphqlRoutes); | |
| 289 | app.route("/", marketplaceRoutes); | |
| 290 | app.route("/", mergeQueueRoutes); | |
| 291 | app.route("/", mirrorsRoutes); | |
| 292 | app.route("/", orgInsightsRoutes); | |
| 293 | app.route("/", packagesRoutes); | |
| 294 | app.route("/", packagesApiRoutes); | |
| 295 | app.route("/", pagesRoutes); | |
| 296 | app.route("/", projectsRoutes); | |
| 297 | app.route("/", protectedTagsRoutes); | |
| 298 | app.route("/", pwaRoutes); | |
| 299 | app.route("/", releasesRoutes); | |
| 300 | app.route("/", requiredChecksRoutes); | |
| 301 | app.route("/", rulesetsRoutes); | |
| 302 | app.route("/", searchRoutes); | |
| 303 | app.route("/", semanticSearchRoutes); | |
| 304 | app.route("/", signingKeysRoutes); | |
| 305 | app.route("/", sponsorsRoutes); | |
| 306 | app.route("/", ssoRoutes); | |
| 307 | app.route("/", symbolsRoutes); | |
| 308 | app.route("/", templatesRoutes); | |
| 309 | app.route("/", trafficRoutes); | |
| 310 | app.route("/", wikisRoutes); | |
| 311 | app.route("/", workflowsRoutes); | |
| 5ff9cc2 | 312 | app.route("/", workflowArtifactsRoutes); |
| 313 | app.route("/", workflowSecretsRoutes); | |
| 0316dbb | 314 | |
| 79136bb | 315 | // Web UI (catch-all, must be last) |
| 316 | app.route("/", webRoutes); | |
| 317 | ||
| 318 | // Global 404 | |
| 319 | app.notFound((c) => { | |
| 320 | return c.html( | |
| 321 | <Layout title="Not Found"> | |
| 322 | <div class="empty-state"> | |
| 323 | <h2>404</h2> | |
| 324 | <p>Page not found.</p> | |
| 325 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 326 | Go home | |
| 327 | </a> | |
| 328 | </div> | |
| 329 | </Layout>, | |
| 330 | 404 | |
| 331 | ); | |
| 332 | }); | |
| 333 | ||
| 334 | // Global error handler | |
| 335 | app.onError((err, c) => { | |
| 80bed05 | 336 | reportError(err, { |
| 337 | requestId: c.get("requestId"), | |
| 338 | path: c.req.path, | |
| 339 | method: c.req.method, | |
| 340 | }); | |
| 79136bb | 341 | return c.html( |
| 342 | <Layout title="Error"> | |
| 343 | <div class="empty-state"> | |
| 344 | <h2>Something went wrong</h2> | |
| 345 | <p>An unexpected error occurred.</p> | |
| 346 | {process.env.NODE_ENV !== "production" && ( | |
| 347 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 348 | {err.message} | |
| 349 | </pre> | |
| 350 | )} | |
| 351 | </div> | |
| 352 | </Layout>, | |
| 353 | 500 | |
| 354 | ); | |
| 355 | }); | |
| 356 | ||
| 357 | export default app; |