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"; |
| b0148e9 | 34 | import marketingRoutes from "./routes/marketing"; |
| 5618f9a | 35 | import seoRoutes from "./routes/seo"; |
| 05cdb85 | 36 | import versionRoutes from "./routes/version"; |
| f295f78 | 37 | import { platformStatus } from "./routes/platform-status"; |
| 16b325c | 38 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 39 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 40 | import legalRoutes from "./routes/legal"; |
| bdbd0de | 41 | import importRoutes from "./routes/import"; |
| 14c3cc8 | 42 | import importBulkRoutes from "./routes/import-bulk"; |
| 43 | import migrationRoutes from "./routes/migrations"; | |
| 44 | import specsRoutes from "./routes/specs"; | |
| 79136bb | 45 | import webRoutes from "./routes/web"; |
| 0316dbb | 46 | import hookRoutes from "./routes/hooks"; |
| 47 | import eventsRoutes from "./routes/events"; | |
| 48 | import passkeyRoutes from "./routes/passkeys"; | |
| 49 | import oauthRoutes from "./routes/oauth"; | |
| 50 | import developerAppsRoutes from "./routes/developer-apps"; | |
| 51 | import themeRoutes from "./routes/theme"; | |
| 52 | import auditRoutes from "./routes/audit"; | |
| 53 | import reactionRoutes from "./routes/reactions"; | |
| 54 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 55 | import deploymentRoutes from "./routes/deployments"; | |
| 56 | import orgRoutes from "./routes/orgs"; | |
| 57 | import notificationRoutes from "./routes/notifications"; | |
| 58 | import onboardingRoutes from "./routes/onboarding"; | |
| 59 | import adminRoutes from "./routes/admin"; | |
| 60 | import advisoriesRoutes from "./routes/advisories"; | |
| 61 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 62 | import aiExplainRoutes from "./routes/ai-explain"; | |
| 63 | import aiTestsRoutes from "./routes/ai-tests"; | |
| 64 | import askRoutes from "./routes/ask"; | |
| 65 | import billingRoutes from "./routes/billing"; | |
| 6778ad2 | 66 | import stripeWebhookRoutes from "./routes/stripe-webhook"; |
| 0316dbb | 67 | import codeScanningRoutes from "./routes/code-scanning"; |
| 68 | import commitStatusesRoutes from "./routes/commit-statuses"; | |
| 69 | import copilotRoutes from "./routes/copilot"; | |
| 70 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 71 | import depsRoutes from "./routes/deps"; | |
| 72 | import discussionsRoutes from "./routes/discussions"; | |
| 73 | import environmentsRoutes from "./routes/environments"; | |
| 74 | import followsRoutes from "./routes/follows"; | |
| 75 | import gatesRoutes from "./routes/gates"; | |
| 76 | import gistsRoutes from "./routes/gists"; | |
| 77 | import graphqlRoutes from "./routes/graphql"; | |
| 2c2163e | 78 | import mcpRoutes from "./routes/mcp"; |
| 0316dbb | 79 | import marketplaceRoutes from "./routes/marketplace"; |
| 80 | import mergeQueueRoutes from "./routes/merge-queue"; | |
| 81 | import mirrorsRoutes from "./routes/mirrors"; | |
| 82 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 83 | import packagesRoutes from "./routes/packages"; | |
| 84 | import packagesApiRoutes from "./routes/packages-api"; | |
| 85 | import pagesRoutes from "./routes/pages"; | |
| 86 | import projectsRoutes from "./routes/projects"; | |
| 87 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 88 | import pwaRoutes from "./routes/pwa"; | |
| 89 | import releasesRoutes from "./routes/releases"; | |
| 90 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 91 | import rulesetsRoutes from "./routes/rulesets"; | |
| 92 | import searchRoutes from "./routes/search"; | |
| 93 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 94 | import signingKeysRoutes from "./routes/signing-keys"; | |
| 95 | import sponsorsRoutes from "./routes/sponsors"; | |
| 96 | import ssoRoutes from "./routes/sso"; | |
| 97 | import symbolsRoutes from "./routes/symbols"; | |
| 98 | import templatesRoutes from "./routes/templates"; | |
| 99 | import trafficRoutes from "./routes/traffic"; | |
| 100 | import wikisRoutes from "./routes/wikis"; | |
| 101 | import workflowsRoutes from "./routes/workflows"; | |
| 5ff9cc2 | 102 | import workflowArtifactsRoutes from "./routes/workflow-artifacts"; |
| 103 | import workflowSecretsRoutes from "./routes/workflow-secrets"; | |
| 59b6fb2 | 104 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 105 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 106 | |
| 107 | const app = new Hono(); | |
| 108 | ||
| 3ef4c9d | 109 | // Request context (request ID, start time) runs before everything else |
| 110 | app.use("*", requestContext); | |
| 05b973e | 111 | // Middleware — compression first (wraps all responses) |
| 112 | app.use("*", compress()); | |
| 113 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 114 | app.use("*", async (c, next) => { | |
| 115 | if (c.req.path.includes(".git/")) return next(); | |
| 116 | return logger()(c, next); | |
| 117 | }); | |
| 79136bb | 118 | app.use("/api/*", cors()); |
| 290ea77 | 119 | |
| 120 | // Force fresh HTML on every request — kills browser HTTP cache holding stale | |
| 121 | // pre-redesign markup. JSON / static assets keep their own cache rules; only | |
| 122 | // text/html responses get the no-cache stamp. Without this, every push to | |
| 123 | // main left users staring at cached 80s-looking pages from before the design | |
| 124 | // landed. | |
| 125 | app.use("*", async (c, next) => { | |
| 126 | await next(); | |
| 127 | const ct = c.res.headers.get("content-type") || ""; | |
| 128 | if (ct.startsWith("text/html")) { | |
| 129 | c.header("cache-control", "no-cache, no-store, must-revalidate"); | |
| 130 | c.header("pragma", "no-cache"); | |
| 131 | c.header("expires", "0"); | |
| 132 | } | |
| 133 | }); | |
| 3ef4c9d | 134 | // Rate-limit API + auth endpoints (generous default) |
| 0316dbb | 135 | app.use("/api/*", rateLimit(120, 60_000, "api")); |
| 136 | app.use("/login", rateLimit(20, 60_000, "login")); | |
| 137 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| 79136bb | 138 | |
| 59b6fb2 | 139 | // CSRF protection — set token on all requests, validate on mutations |
| 140 | app.use("*", csrfToken); | |
| 141 | app.use("*", csrfProtect); | |
| 142 | ||
| 45e31d0 | 143 | // Rate limit auth routes |
| 144 | app.use("/login", authRateLimit); | |
| 145 | app.use("/register", authRateLimit); | |
| 146 | ||
| 59b6fb2 | 147 | // Rate limit git operations |
| 148 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 149 | ||
| 150 | // Rate limit search | |
| 151 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 152 | app.use("/explore", searchRateLimit); | |
| 79136bb | 153 | |
| 154 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 155 | app.route("/", gitRoutes); | |
| 156 | ||
| 45e31d0 | 157 | // REST API v1 (legacy) |
| 79136bb | 158 | app.route("/", apiRoutes); |
| 159 | ||
| 0316dbb | 160 | // REST API v2 (basePath /api/v2) |
| 161 | app.route("/", apiV2Routes); | |
| 162 | ||
| ad6d4ad | 163 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 164 | app.route("/", hookRoutes); | |
| 21f8dbd | 165 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 166 | |
| 45e31d0 | 167 | // API documentation |
| 168 | app.route("/", apiDocsRoutes); | |
| 79136bb | 169 | |
| 170 | // Auth routes (register, login, logout) | |
| 171 | app.route("/", authRoutes); | |
| 172 | ||
| 173 | // Settings routes (profile, SSH keys) | |
| 174 | app.route("/", settingsRoutes); | |
| 175 | ||
| 7298a17 | 176 | // 2FA / TOTP settings (Block B4) |
| 177 | app.route("/", settings2faRoutes); | |
| 178 | ||
| 2df1f8c | 179 | // WebAuthn / passkey routes (Block B5) |
| 180 | app.route("/", passkeyRoutes); | |
| 181 | ||
| 058d752 | 182 | // OAuth 2.0 provider (Block B6) |
| 183 | app.route("/", oauthRoutes); | |
| 184 | app.route("/", developerAppsRoutes); | |
| 185 | ||
| 6fc53bd | 186 | // Theme toggle (dark/light cookie) |
| 187 | app.route("/", themeRoutes); | |
| 188 | ||
| 189 | // Audit log UI | |
| 190 | app.route("/", auditRoutes); | |
| 191 | ||
| 192 | // Reactions API (issues, PRs, comments) | |
| 193 | app.route("/", reactionRoutes); | |
| 194 | ||
| 24cf2ca | 195 | // Saved replies (per-user canned comment templates) |
| 196 | app.route("/", savedReplyRoutes); | |
| 197 | ||
| 198 | // Environments + deployment history UI | |
| 199 | app.route("/", deploymentRoutes); | |
| 200 | ||
| 6563f0a | 201 | // Organizations + teams (Block B1) |
| 202 | app.route("/", orgRoutes); | |
| 203 | ||
| c81ab7a | 204 | // API tokens |
| 205 | app.route("/", tokenRoutes); | |
| 206 | ||
| 59b6fb2 | 207 | // Notifications |
| 3ef4c9d | 208 | app.route("/", notificationRoutes); |
| 209 | ||
| 79136bb | 210 | // Repo settings (description, visibility, delete) |
| 211 | app.route("/", repoSettings); | |
| 212 | ||
| 23d1a81 | 213 | // Repo collaborators (add/list/remove) |
| 214 | app.route("/", collaboratorRoutes); | |
| 215 | ||
| 04f6b7f | 216 | // Team-based repo collaborators (invite a whole team) |
| 217 | app.route("/", teamCollaboratorRoutes); | |
| 218 | ||
| 219 | // Collaborator invite accept flow (token-based) | |
| 220 | app.route("/", invitesRoutes); | |
| 221 | ||
| 222 | // Real-time SSE endpoint (topic-based live updates) | |
| 223 | app.route("/", liveEventsRoutes); | |
| 224 | ||
| c81ab7a | 225 | // Webhooks management |
| 226 | app.route("/", webhookRoutes); | |
| 227 | ||
| 79136bb | 228 | // Compare view (branch diffs) |
| 229 | app.route("/", compareRoutes); | |
| 230 | ||
| 231 | // Issue tracker | |
| 232 | app.route("/", issueRoutes); | |
| 233 | ||
| 0074234 | 234 | // Pull requests |
| 235 | app.route("/", pullRoutes); | |
| 236 | ||
| c81ab7a | 237 | // Fork |
| 238 | app.route("/", forkRoutes); | |
| 239 | ||
| 0074234 | 240 | // Web file editor |
| 241 | app.route("/", editorRoutes); | |
| 242 | ||
| 43de941 | 243 | // Contributors |
| 244 | app.route("/", contributorRoutes); | |
| 245 | ||
| 699e5c7 | 246 | // Health liveness + metrics endpoints |
| 2c34075 | 247 | app.route("/", healthRoutes); |
| 248 | ||
| f295f78 | 249 | // Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md) |
| 250 | app.route("/api/platform-status", platformStatus); | |
| 251 | ||
| 2316be6 | 252 | // Public /status — human-readable platform health page |
| 253 | app.route("/", statusRoutes); | |
| 254 | ||
| 80bed05 | 255 | // /help — quickstart + API cheatsheet |
| 256 | app.route("/", helpRoutes); | |
| 257 | ||
| b0148e9 | 258 | // /pricing, /features, /about — marketing surface |
| 259 | app.route("/", marketingRoutes); | |
| 260 | ||
| 5618f9a | 261 | // SEO: robots.txt + sitemap.xml |
| 262 | app.route("/", seoRoutes); | |
| 263 | ||
| 05cdb85 | 264 | // /api/version — live build SHA + uptime; client poller uses this to |
| 265 | // surface 'New version available — reload' banners on deploy. | |
| 266 | app.route("/", versionRoutes); | |
| 267 | ||
| 699e5c7 | 268 | // Health dashboard (per-repo health page) |
| 269 | app.route("/", healthDashboardRoutes); | |
| 270 | ||
| 16b325c | 271 | // Insights (time-travel, dependencies, rollback) |
| 272 | app.route("/", insightRoutes); | |
| 273 | ||
| f1ab587 | 274 | // Command center dashboard |
| 275 | app.route("/", dashboardRoutes); | |
| 276 | ||
| 36b4cbd | 277 | // Legal pages (terms, privacy, AUP) |
| 278 | app.route("/", legalRoutes); | |
| 279 | ||
| bdbd0de | 280 | // GitHub import / migration |
| 281 | app.route("/", importRoutes); | |
| 14c3cc8 | 282 | app.route("/", importBulkRoutes); |
| 283 | app.route("/", migrationRoutes); | |
| 284 | ||
| 285 | // Spec-to-PR (experimental AI-generated draft PRs) | |
| 286 | app.route("/", specsRoutes); | |
| bdbd0de | 287 | |
| c81ab7a | 288 | // Explore page |
| 289 | app.route("/", exploreRoutes); | |
| 290 | ||
| 59b6fb2 | 291 | // Onboarding |
| 292 | app.route("/", onboardingRoutes); | |
| 293 | ||
| 0316dbb | 294 | // Admin + feature routes |
| 295 | app.route("/", adminRoutes); | |
| 296 | app.route("/", advisoriesRoutes); | |
| 297 | app.route("/", aiChangelogRoutes); | |
| 298 | app.route("/", aiExplainRoutes); | |
| 299 | app.route("/", aiTestsRoutes); | |
| 300 | app.route("/", askRoutes); | |
| 301 | app.route("/", billingRoutes); | |
| 6778ad2 | 302 | app.route("/", stripeWebhookRoutes); |
| 0316dbb | 303 | app.route("/", codeScanningRoutes); |
| 304 | app.route("/", commitStatusesRoutes); | |
| 305 | app.route("/", copilotRoutes); | |
| 306 | app.route("/", depUpdaterRoutes); | |
| 307 | app.route("/", depsRoutes); | |
| 308 | app.route("/", discussionsRoutes); | |
| 309 | app.route("/", environmentsRoutes); | |
| 310 | app.route("/", followsRoutes); | |
| 311 | app.route("/", gatesRoutes); | |
| 312 | app.route("/", gistsRoutes); | |
| 313 | app.route("/", graphqlRoutes); | |
| 2c2163e | 314 | app.route("/", mcpRoutes); |
| 0316dbb | 315 | app.route("/", marketplaceRoutes); |
| 316 | app.route("/", mergeQueueRoutes); | |
| 317 | app.route("/", mirrorsRoutes); | |
| 318 | app.route("/", orgInsightsRoutes); | |
| 319 | app.route("/", packagesRoutes); | |
| 320 | app.route("/", packagesApiRoutes); | |
| 321 | app.route("/", pagesRoutes); | |
| 322 | app.route("/", projectsRoutes); | |
| 323 | app.route("/", protectedTagsRoutes); | |
| 324 | app.route("/", pwaRoutes); | |
| 325 | app.route("/", releasesRoutes); | |
| 326 | app.route("/", requiredChecksRoutes); | |
| 327 | app.route("/", rulesetsRoutes); | |
| 328 | app.route("/", searchRoutes); | |
| 329 | app.route("/", semanticSearchRoutes); | |
| 330 | app.route("/", signingKeysRoutes); | |
| 331 | app.route("/", sponsorsRoutes); | |
| 332 | app.route("/", ssoRoutes); | |
| 333 | app.route("/", symbolsRoutes); | |
| 334 | app.route("/", templatesRoutes); | |
| 335 | app.route("/", trafficRoutes); | |
| 336 | app.route("/", wikisRoutes); | |
| 337 | app.route("/", workflowsRoutes); | |
| 5ff9cc2 | 338 | app.route("/", workflowArtifactsRoutes); |
| 339 | app.route("/", workflowSecretsRoutes); | |
| 0316dbb | 340 | |
| 79136bb | 341 | // Web UI (catch-all, must be last) |
| 342 | app.route("/", webRoutes); | |
| 343 | ||
| 344 | // Global 404 | |
| 345 | app.notFound((c) => { | |
| 346 | return c.html( | |
| 347 | <Layout title="Not Found"> | |
| e1db10e | 348 | <div class="error-page"> |
| 349 | <div class="error-page-code">404</div> | |
| 350 | <div class="eyebrow">Not found</div> | |
| 351 | <h1 class="display error-page-title"> | |
| 352 | That page <span class="gradient-text">isn't here.</span> | |
| 353 | </h1> | |
| 354 | <p class="error-page-sub"> | |
| 355 | The URL might be wrong, the resource might have moved, or you | |
| 356 | might not have permission to see it. | |
| 357 | </p> | |
| 358 | <div class="error-page-actions"> | |
| 359 | <a href="/" class="btn btn-primary btn-lg">Go home</a> | |
| 360 | <a href="/explore" class="btn btn-ghost btn-lg">Explore repos</a> | |
| 361 | </div> | |
| 362 | <div class="error-page-meta"> | |
| 363 | <span class="meta-mono">{c.req.method} {c.req.path}</span> | |
| 364 | </div> | |
| 79136bb | 365 | </div> |
| 366 | </Layout>, | |
| 367 | 404 | |
| 368 | ); | |
| 369 | }); | |
| 370 | ||
| 371 | // Global error handler | |
| 372 | app.onError((err, c) => { | |
| 80bed05 | 373 | reportError(err, { |
| 374 | requestId: c.get("requestId"), | |
| 375 | path: c.req.path, | |
| 376 | method: c.req.method, | |
| 377 | }); | |
| e1db10e | 378 | const requestId = c.get("requestId" as never) as string | undefined; |
| 79136bb | 379 | return c.html( |
| 380 | <Layout title="Error"> | |
| e1db10e | 381 | <div class="error-page"> |
| 382 | <div class="error-page-code error-page-code-err">500</div> | |
| 383 | <div class="eyebrow" style="color:var(--red)">Server error</div> | |
| 384 | <h1 class="display error-page-title"> | |
| 385 | Something <span class="gradient-text">went wrong.</span> | |
| 386 | </h1> | |
| 387 | <p class="error-page-sub"> | |
| 388 | The error has been reported. Try again — if it persists, file | |
| 389 | an issue with the request ID below. | |
| 390 | </p> | |
| 391 | <div class="error-page-actions"> | |
| 392 | <a href={c.req.path} class="btn btn-primary btn-lg">Retry</a> | |
| 393 | <a href="/" class="btn btn-ghost btn-lg">Go home</a> | |
| 394 | </div> | |
| 395 | {requestId && ( | |
| 396 | <div class="error-page-meta"> | |
| 397 | <span class="meta-mono">request-id: {requestId}</span> | |
| 398 | </div> | |
| 399 | )} | |
| 79136bb | 400 | {process.env.NODE_ENV !== "production" && ( |
| e1db10e | 401 | <pre class="error-page-trace">{err.message}</pre> |
| 79136bb | 402 | )} |
| 403 | </div> | |
| 404 | </Layout>, | |
| 405 | 500 | |
| 406 | ); | |
| 407 | }); | |
| 408 | ||
| 409 | export default app; |