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"; |
| f1ffd50 | 5 | import { etag } from "hono/etag"; |
| c63b860 | 6 | // BLOCK O2 — shared error-page surface (404 / 500 / 403). |
| 7 | import { NotFoundPage, ServerErrorPage } from "./views/error-page"; | |
| 80bed05 | 8 | import { reportError } from "./lib/observability"; |
| 3ef4c9d | 9 | import { requestContext } from "./middleware/request-context"; |
| 10 | import { rateLimit } from "./middleware/rate-limit"; | |
| 79136bb | 11 | import gitRoutes from "./routes/git"; |
| 12 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 13 | import apiV2Routes from "./routes/api-v2"; |
| 14 | import apiDocsRoutes from "./routes/api-docs"; | |
| 4a80519 | 15 | import buildAgentSpecRoutes from "./routes/build-agent-spec"; |
| a6ff0f2 | 16 | import pullsDashboardRoutes from "./routes/pulls-dashboard"; |
| e9aa4d8 | 17 | import issuesDashboardRoutes from "./routes/issues-dashboard"; |
| 18 | import inboxRoutes from "./routes/inbox"; | |
| 19 | import activityRoutes from "./routes/activity"; | |
| 79136bb | 20 | import authRoutes from "./routes/auth"; |
| c63b860 | 21 | import passwordResetRoutes from "./routes/password-reset"; |
| 22 | import emailVerificationRoutes from "./routes/email-verification"; | |
| cd4f63b | 23 | import magicLinkRoutes from "./routes/magic-link"; |
| 79136bb | 24 | import settingsRoutes from "./routes/settings"; |
| 7298a17 | 25 | import settings2faRoutes from "./routes/settings-2fa"; |
| e75eddc | 26 | import settingsAgentsRoutes from "./routes/settings-agents"; |
| 1d4ff60 | 27 | import settingsIntegrationsRoutes from "./routes/settings-integrations"; |
| 28 | import integrationsChatRoutes from "./routes/integrations-chat"; | |
| e75eddc | 29 | import agentsRoutes from "./routes/agents"; |
| 79136bb | 30 | import issueRoutes from "./routes/issues"; |
| 31 | import repoSettings from "./routes/repo-settings"; | |
| 23d1a81 | 32 | import collaboratorRoutes from "./routes/collaborators"; |
| 04f6b7f | 33 | import teamCollaboratorRoutes from "./routes/team-collaborators"; |
| 34 | import invitesRoutes from "./routes/invites"; | |
| 35 | import liveEventsRoutes from "./routes/live-events"; | |
| 3c03977 | 36 | import prLiveRoutes from "./routes/pr-live"; |
| 79136bb | 37 | import compareRoutes from "./routes/compare"; |
| 0074234 | 38 | import pullRoutes from "./routes/pulls"; |
| 79ed944 | 39 | import prSandboxRoutes from "./routes/pr-sandbox"; |
| 0074234 | 40 | import editorRoutes from "./routes/editor"; |
| c81ab7a | 41 | import forkRoutes from "./routes/fork"; |
| 42 | import webhookRoutes from "./routes/webhooks"; | |
| 43 | import exploreRoutes from "./routes/explore"; | |
| 44 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 45 | import contributorRoutes from "./routes/contributors"; |
| 699e5c7 | 46 | import healthRoutes from "./routes/health-probe"; |
| 47 | import healthDashboardRoutes from "./routes/health"; | |
| 2316be6 | 48 | import statusRoutes from "./routes/status"; |
| b1be050 | 49 | import adminStatusRoutes from "./routes/admin-status"; |
| 80bed05 | 50 | import helpRoutes from "./routes/help"; |
| b0148e9 | 51 | import marketingRoutes from "./routes/marketing"; |
| 5f2e749 | 52 | import pricingRoutes from "./routes/pricing"; |
| 5618f9a | 53 | import seoRoutes from "./routes/seo"; |
| 05cdb85 | 54 | import versionRoutes from "./routes/version"; |
| f295f78 | 55 | import { platformStatus } from "./routes/platform-status"; |
| 52ad8b1 | 56 | import publicStatsRoutes from "./routes/public-stats"; |
| 57 | import demoRoutes from "./routes/demo"; | |
| 16b325c | 58 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 59 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 60 | import legalRoutes from "./routes/legal"; |
| 4b66018 | 61 | import legalDmcaRoutes from "./routes/legal/dmca"; |
| 62 | import legalTermsRoutes from "./routes/legal/terms"; | |
| 63 | import legalPrivacyRoutes from "./routes/legal/privacy"; | |
| 64 | import legalAcceptableUseRoutes from "./routes/legal/acceptable-use"; | |
| bdbd0de | 65 | import importRoutes from "./routes/import"; |
| 14c3cc8 | 66 | import importBulkRoutes from "./routes/import-bulk"; |
| f390cfa | 67 | import importSecretsRoutes from "./routes/import-secrets"; |
| 14c3cc8 | 68 | import migrationRoutes from "./routes/migrations"; |
| 69 | import specsRoutes from "./routes/specs"; | |
| 23d0abf | 70 | import refactorRoutes from "./routes/refactors"; |
| 79136bb | 71 | import webRoutes from "./routes/web"; |
| 0316dbb | 72 | import hookRoutes from "./routes/hooks"; |
| 73 | import eventsRoutes from "./routes/events"; | |
| 74 | import passkeyRoutes from "./routes/passkeys"; | |
| 75 | import oauthRoutes from "./routes/oauth"; | |
| 76 | import developerAppsRoutes from "./routes/developer-apps"; | |
| 77 | import themeRoutes from "./routes/theme"; | |
| 78 | import auditRoutes from "./routes/audit"; | |
| 79 | import reactionRoutes from "./routes/reactions"; | |
| 80 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 81 | import deploymentRoutes from "./routes/deployments"; | |
| 82 | import orgRoutes from "./routes/orgs"; | |
| 83 | import notificationRoutes from "./routes/notifications"; | |
| 84 | import onboardingRoutes from "./routes/onboarding"; | |
| 85 | import adminRoutes from "./routes/admin"; | |
| f764c07 | 86 | import adminDeploysRoutes from "./routes/admin-deploys"; |
| 87 | import adminDeploysPageRoutes from "./routes/admin-deploys-page"; | |
| 9dd96b9 | 88 | import adminOpsRoutes from "./routes/admin-ops"; |
| f2c00b4 | 89 | import adminSelfHostRoutes from "./routes/admin-self-host"; |
| 826eccf | 90 | import adminDiagnoseRoutes from "./routes/admin-diagnose"; |
| 509c376 | 91 | import adminIntegrationsRoutes from "./routes/admin-integrations"; |
| 79ed944 | 92 | import adminAdvancementRoutes from "./routes/admin-advancement"; |
| 0316dbb | 93 | import advisoriesRoutes from "./routes/advisories"; |
| 94 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 95 | import aiExplainRoutes from "./routes/ai-explain"; | |
| 96 | import aiTestsRoutes from "./routes/ai-tests"; | |
| 97 | import askRoutes from "./routes/ask"; | |
| 38d31d3 | 98 | import repoChatRoutes from "./routes/repo-chat"; |
| 0316dbb | 99 | import billingRoutes from "./routes/billing"; |
| 8809b87 | 100 | import billingUsageRoutes from "./routes/billing-usage"; |
| 6778ad2 | 101 | import stripeWebhookRoutes from "./routes/stripe-webhook"; |
| 0316dbb | 102 | import codeScanningRoutes from "./routes/code-scanning"; |
| 103 | import commitStatusesRoutes from "./routes/commit-statuses"; | |
| 104 | import copilotRoutes from "./routes/copilot"; | |
| 105 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 106 | import depsRoutes from "./routes/deps"; | |
| 107 | import discussionsRoutes from "./routes/discussions"; | |
| 108 | import environmentsRoutes from "./routes/environments"; | |
| 4bbacbe | 109 | import previewsRoutes from "./routes/previews"; |
| 79ed944 | 110 | import docsTrackingRoutes from "./routes/docs-tracking"; |
| 0316dbb | 111 | import followsRoutes from "./routes/follows"; |
| 112 | import gatesRoutes from "./routes/gates"; | |
| 113 | import gistsRoutes from "./routes/gists"; | |
| 114 | import graphqlRoutes from "./routes/graphql"; | |
| 2c2163e | 115 | import mcpRoutes from "./routes/mcp"; |
| 0316dbb | 116 | import marketplaceRoutes from "./routes/marketplace"; |
| 117 | import mergeQueueRoutes from "./routes/merge-queue"; | |
| 118 | import mirrorsRoutes from "./routes/mirrors"; | |
| 119 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 120 | import packagesRoutes from "./routes/packages"; | |
| 121 | import packagesApiRoutes from "./routes/packages-api"; | |
| 122 | import pagesRoutes from "./routes/pages"; | |
| 123 | import projectsRoutes from "./routes/projects"; | |
| 124 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 125 | import pwaRoutes from "./routes/pwa"; | |
| 46d6165 | 126 | import installRoutes from "./routes/install"; |
| cd4f63b | 127 | import dxtRoutes from "./routes/dxt"; |
| 662ce86 | 128 | import connectClaudeRoutes from "./routes/connect-claude"; |
| 0316dbb | 129 | import releasesRoutes from "./routes/releases"; |
| 130 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 131 | import rulesetsRoutes from "./routes/rulesets"; | |
| 132 | import searchRoutes from "./routes/search"; | |
| 133 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 134 | import signingKeysRoutes from "./routes/signing-keys"; | |
| 135 | import sponsorsRoutes from "./routes/sponsors"; | |
| 136 | import ssoRoutes from "./routes/sso"; | |
| 46d6165 | 137 | import githubOauthRoutes from "./routes/github-oauth"; |
| 582cdac | 138 | import googleOauthRoutes from "./routes/google-oauth"; |
| 0316dbb | 139 | import symbolsRoutes from "./routes/symbols"; |
| 140 | import templatesRoutes from "./routes/templates"; | |
| 141 | import trafficRoutes from "./routes/traffic"; | |
| 142 | import wikisRoutes from "./routes/wikis"; | |
| 143 | import workflowsRoutes from "./routes/workflows"; | |
| 5ff9cc2 | 144 | import workflowArtifactsRoutes from "./routes/workflow-artifacts"; |
| 145 | import workflowSecretsRoutes from "./routes/workflow-secrets"; | |
| 46d6165 | 146 | import sleepModeRoutes from "./routes/sleep-mode"; |
| 56801e1 | 147 | import standupRoutes from "./routes/standups"; |
| 52ad8b1 | 148 | import vsGithubRoutes from "./routes/vs-github"; |
| 45f3b73 | 149 | import voiceRoutes from "./routes/voice-to-pr"; |
| cd4f63b | 150 | import playgroundRoutes from "./routes/playground"; |
| 59b6fb2 | 151 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 152 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 153 | |
| 2316901 | 154 | import type { AuthEnv } from "./middleware/auth"; |
| bf19c50 | 155 | import { softAuth } from "./middleware/auth"; |
| 2316901 | 156 | |
| 157 | const app = new Hono<AuthEnv>(); | |
| 79136bb | 158 | |
| 3ef4c9d | 159 | // Request context (request ID, start time) runs before everything else |
| 160 | app.use("*", requestContext); | |
| 05b973e | 161 | // Middleware — compression first (wraps all responses) |
| 162 | app.use("*", compress()); | |
| f1ffd50 | 163 | |
| 164 | // ETag middleware — returns 304 Not Modified on unchanged responses. | |
| 165 | // Saves ~95% bandwidth on repeat visits. Skipped on git protocol + | |
| 166 | // SSE + the API surface where it would interfere with streaming. | |
| 167 | app.use("*", async (c, next) => { | |
| 168 | const p = c.req.path; | |
| 169 | if ( | |
| 170 | p.includes(".git/") || | |
| 171 | p.startsWith("/live-events") || | |
| 172 | p.startsWith("/api/events/deploy") || | |
| 3c03977 | 173 | p.startsWith("/admin/status") || |
| 174 | // PR live co-editing SSE stream — never etag streaming responses. | |
| 175 | /^\/api\/v2\/pulls\/[^/]+\/live(\/|$)/.test(p) | |
| f1ffd50 | 176 | ) { |
| 177 | return next(); | |
| 178 | } | |
| 179 | return etag()(c, next); | |
| 180 | }); | |
| 181 | ||
| 182 | // Cache-Control middleware — sets sensible defaults on public, anonymous | |
| 183 | // requests. Crontech (when wired as our edge layer) and downstream | |
| 184 | // browsers will honor these. Auth'd users get private,no-store | |
| 185 | // automatically — we never cache responses tied to a session. | |
| 186 | app.use("*", async (c, next) => { | |
| 187 | await next(); | |
| 188 | // Don't overwrite explicit headers set by route handlers — BUT the | |
| 189 | // ETag middleware unconditionally sets "private, no-cache, must- | |
| 190 | // revalidate" so we have to treat that specific value as "no | |
| 191 | // policy chosen yet" and apply ours. Any route that explicitly set | |
| 192 | // a different cache-control wins. | |
| 193 | const existing = c.res.headers.get("cache-control"); | |
| 194 | const etagDefault = | |
| 195 | existing === "private, no-cache, must-revalidate" || | |
| 196 | existing === "no-cache"; | |
| 197 | if (existing && !etagDefault) return; | |
| 198 | // Anything past auth: private + no-store (avoid leaking session | |
| 199 | // content into shared caches). softAuth runs before this on the | |
| 200 | // request, but the response side is what we're stamping. | |
| 201 | const hasSession = c.req.header("cookie")?.includes("session=") ?? false; | |
| 202 | const p = c.req.path; | |
| 203 | // Always private for known-authed paths regardless of cookie. | |
| 204 | if ( | |
| 205 | p.startsWith("/admin") || | |
| 206 | p.startsWith("/settings") || | |
| 207 | p.startsWith("/dashboard") || | |
| 208 | p.startsWith("/notifications") || | |
| 209 | p.startsWith("/connect/") || | |
| 210 | hasSession | |
| 211 | ) { | |
| 212 | c.res.headers.set("cache-control", "private, no-store"); | |
| 213 | return; | |
| 214 | } | |
| 215 | // Public marketing surfaces — short edge cache, longer browser cache, | |
| 216 | // stale-while-revalidate so the user never waits on a stale fetch. | |
| 217 | const isMarketing = | |
| 218 | p === "/" || | |
| 219 | p === "/features" || | |
| 220 | p === "/pricing" || | |
| 221 | p === "/about" || | |
| 222 | p === "/vs-github" || | |
| 223 | p === "/explore" || | |
| 224 | p === "/help" || | |
| 225 | p === "/changelog" || | |
| 226 | p.startsWith("/legal/") || | |
| 227 | p === "/terms" || | |
| 228 | p === "/privacy" || | |
| 229 | p === "/acceptable-use" || | |
| 230 | p.startsWith("/docs/"); | |
| 231 | if (isMarketing) { | |
| 232 | c.res.headers.set( | |
| 233 | "cache-control", | |
| 234 | "public, max-age=60, s-maxage=300, stale-while-revalidate=86400" | |
| 235 | ); | |
| 236 | return; | |
| 237 | } | |
| 238 | // Public repo browse pages — cache aggressively. Edge invalidates | |
| 239 | // on push via the post-receive hook (future Crontech surge purge). | |
| 240 | if (/^\/[^/]+\/[^/]+(\/.*)?$/.test(p) && c.req.method === "GET") { | |
| 241 | c.res.headers.set( | |
| 242 | "cache-control", | |
| 243 | "public, max-age=30, s-maxage=120, stale-while-revalidate=600" | |
| 244 | ); | |
| 245 | return; | |
| 246 | } | |
| 247 | // Default: don't cache anything we haven't explicitly opted in. | |
| 248 | c.res.headers.set("cache-control", "private, no-store"); | |
| 249 | }); | |
| 05b973e | 250 | // Logger only on non-git routes to avoid overhead on clone/push |
| 251 | app.use("*", async (c, next) => { | |
| 252 | if (c.req.path.includes(".git/")) return next(); | |
| 253 | return logger()(c, next); | |
| 254 | }); | |
| 79136bb | 255 | app.use("/api/*", cors()); |
| bf19c50 | 256 | // Global softAuth — populates c.get("user") for every downstream middleware |
| 257 | // + route. This was previously per-route, which meant rate-limit middleware | |
| 258 | // (and anything else inspecting auth state) always saw a null user. Keep | |
| 259 | // individual routes free to add requireAuth on top for hard gating; this | |
| 260 | // just establishes the user object cheaply. | |
| 261 | app.use("*", softAuth); | |
| 290ea77 | 262 | |
| 36cc17a | 263 | // Force-revalidate HTML on every request — kills browser cache holding stale |
| 290ea77 | 264 | // pre-redesign markup. JSON / static assets keep their own cache rules; only |
| 265 | // text/html responses get the no-cache stamp. Without this, every push to | |
| 266 | // main left users staring at cached 80s-looking pages from before the design | |
| 267 | // landed. | |
| 36cc17a | 268 | // |
| 269 | // We deliberately use `private, no-cache, must-revalidate` rather than | |
| 270 | // `no-store`. `no-store` disables Safari/Chrome's back-forward cache (bfcache), | |
| 271 | // which makes every Back/Forward press a cold server round-trip — that | |
| 272 | // contributed to the "every nav feels like a fresh login" UX complaint. | |
| 273 | // `no-cache` still revalidates on direct fetch but lets bfcache hold the | |
| 274 | // page in memory between navigations. | |
| 290ea77 | 275 | app.use("*", async (c, next) => { |
| 276 | await next(); | |
| 277 | const ct = c.res.headers.get("content-type") || ""; | |
| 278 | if (ct.startsWith("text/html")) { | |
| 36cc17a | 279 | c.header("cache-control", "private, no-cache, must-revalidate"); |
| 290ea77 | 280 | } |
| 281 | }); | |
| 826eccf | 282 | // Rate-limit API + auth endpoints. |
| 283 | // | |
| a41e675 | 284 | // `/api/*`: 1000/min per IP — generous so an admin clicking around the |
| 285 | // operator console (or a CDN/proxy concentrating multiple users behind one | |
| 286 | // IP) doesn't hit the wall. Bot-resistant headroom comes from the auth | |
| 287 | // rate limits below, not this one. | |
| 288 | // | |
| 289 | // `authedMultiplier` is set but only fires when an upstream middleware has | |
| 290 | // already populated c.get("user") — most app.use() chains apply softAuth | |
| 291 | // per-route, so the multiplier is best-effort. Keep the anonymous base | |
| 292 | // high enough that humans never feel it. | |
| 293 | // | |
| 294 | // Skip-paths: dashboard plumbing endpoints that the layout polls on a | |
| 295 | // fixed cadence and that we don't want consuming any bucket: | |
| 296 | // /api/version — layout polls every 15s | |
| 826eccf | 297 | // /api/notifications/count — nav bell unread-count fetcher |
| 298 | // /pwa/vapid-public-key — fetched once per push-notification opt-in | |
| 299 | app.use( | |
| 300 | "/api/*", | |
| a41e675 | 301 | rateLimit(1000, 60_000, "api", { |
| 826eccf | 302 | authedMultiplier: 4, |
| 303 | skipPaths: ["/api/version", "/api/notifications/count", "/pwa/vapid-public-key"], | |
| 304 | }) | |
| 305 | ); | |
| 0316dbb | 306 | app.use("/login", rateLimit(20, 60_000, "login")); |
| 307 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| c63b860 | 308 | // BLOCK P1 — throttle forgot-password to deter enumeration + mail spam. |
| 309 | app.use("/forgot-password", rateLimit(5, 60_000, "forgot-password")); | |
| cd4f63b | 310 | // BLOCK Q2 — throttle magic-link sign-in for the same reason. |
| 311 | app.use("/login/magic", rateLimit(5, 60_000, "magic-link")); | |
| 79136bb | 312 | |
| 59b6fb2 | 313 | // CSRF protection — set token on all requests, validate on mutations |
| 314 | app.use("*", csrfToken); | |
| 315 | app.use("*", csrfProtect); | |
| 316 | ||
| 45e31d0 | 317 | // Rate limit auth routes |
| 318 | app.use("/login", authRateLimit); | |
| 319 | app.use("/register", authRateLimit); | |
| 320 | ||
| 59b6fb2 | 321 | // Rate limit git operations |
| 322 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 323 | ||
| 324 | // Rate limit search | |
| 325 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 326 | app.use("/explore", searchRateLimit); | |
| 79136bb | 327 | |
| 328 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 329 | app.route("/", gitRoutes); | |
| 330 | ||
| 45e31d0 | 331 | // REST API v1 (legacy) |
| 79136bb | 332 | app.route("/", apiRoutes); |
| 333 | ||
| 52ad8b1 | 334 | // Block L3 — /demo + /api/v2/demo/* live demo endpoints. Mounted BEFORE |
| 335 | // apiV2Routes so the /api/v2/demo/* JSON endpoints win over the v2 base | |
| 336 | // router's catch-shape, and BEFORE adminRoutes so the live /demo page | |
| 337 | // wins over the legacy /demo redirect in src/routes/admin.tsx. | |
| 338 | app.route("/", demoRoutes); | |
| 339 | ||
| 0316dbb | 340 | // REST API v2 (basePath /api/v2) |
| 341 | app.route("/", apiV2Routes); | |
| 342 | ||
| e75eddc | 343 | // Agent multiplayer v1 — /api/v2/agents/* (sessions, leases, usage). |
| 344 | // Mounted alongside apiV2Routes (its own basePath, no path conflict). | |
| 345 | app.route("/", agentsRoutes); | |
| 346 | ||
| ad6d4ad | 347 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 348 | app.route("/", hookRoutes); | |
| 21f8dbd | 349 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 350 | |
| 45e31d0 | 351 | // API documentation |
| 352 | app.route("/", apiDocsRoutes); | |
| 4a80519 | 353 | app.route("/", buildAgentSpecRoutes); |
| a6ff0f2 | 354 | // PR command center — global PR dashboard with AI/GateTest/auto-merge signal |
| 355 | app.route("/", pullsDashboardRoutes); | |
| e9aa4d8 | 356 | // Issue command center — global issue dashboard with AI-triage + autopilot signal |
| 357 | app.route("/", issuesDashboardRoutes); | |
| 358 | // Personal activity timeline — every event across the user's repos, with | |
| 359 | // AI-driven events surfaced separately (the Gluecron differentiator). | |
| 360 | app.route("/", activityRoutes); | |
| 361 | // Unified inbox — mentions + review requests + CI failures + AI events in one timeline | |
| 362 | app.route("/", inboxRoutes); | |
| 56801e1 | 363 | // AI standup feed — daily / weekly Claude-generated team brief |
| 364 | app.route("/", standupRoutes); | |
| 79136bb | 365 | |
| 366 | // Auth routes (register, login, logout) | |
| 367 | app.route("/", authRoutes); | |
| 368 | ||
| c63b860 | 369 | // BLOCK P1 — Password reset (forgot-password + reset-password) |
| 370 | app.route("/", passwordResetRoutes); | |
| 371 | ||
| 372 | // BLOCK P2 — Email verification (verify-email + resend) | |
| 373 | app.route("/", emailVerificationRoutes); | |
| 374 | ||
| cd4f63b | 375 | // BLOCK Q2 — Magic-link sign-in (/login/magic + callback) |
| 376 | app.route("/", magicLinkRoutes); | |
| 377 | ||
| 79136bb | 378 | // Settings routes (profile, SSH keys) |
| 379 | app.route("/", settingsRoutes); | |
| 380 | ||
| 7298a17 | 381 | // 2FA / TOTP settings (Block B4) |
| 382 | app.route("/", settings2faRoutes); | |
| 383 | ||
| e75eddc | 384 | // Agent multiplayer — /settings/agents management UI |
| 385 | app.route("/", settingsAgentsRoutes); | |
| 386 | ||
| 1d4ff60 | 387 | // Chat integrations — Slack / Discord / Teams (/settings/integrations |
| 388 | // + /api/v2/integrations/{slack,discord}/*). See src/lib/chat-bot.ts. | |
| 389 | app.route("/", settingsIntegrationsRoutes); | |
| 390 | app.route("/", integrationsChatRoutes); | |
| 391 | ||
| 2df1f8c | 392 | // WebAuthn / passkey routes (Block B5) |
| 393 | app.route("/", passkeyRoutes); | |
| 394 | ||
| 058d752 | 395 | // OAuth 2.0 provider (Block B6) |
| 396 | app.route("/", oauthRoutes); | |
| 397 | app.route("/", developerAppsRoutes); | |
| 398 | ||
| 6fc53bd | 399 | // Theme toggle (dark/light cookie) |
| 400 | app.route("/", themeRoutes); | |
| 401 | ||
| 402 | // Audit log UI | |
| 403 | app.route("/", auditRoutes); | |
| 404 | ||
| 405 | // Reactions API (issues, PRs, comments) | |
| 406 | app.route("/", reactionRoutes); | |
| 407 | ||
| 24cf2ca | 408 | // Saved replies (per-user canned comment templates) |
| 409 | app.route("/", savedReplyRoutes); | |
| 410 | ||
| 411 | // Environments + deployment history UI | |
| 412 | app.route("/", deploymentRoutes); | |
| 413 | ||
| 6563f0a | 414 | // Organizations + teams (Block B1) |
| 415 | app.route("/", orgRoutes); | |
| 416 | ||
| c81ab7a | 417 | // API tokens |
| 418 | app.route("/", tokenRoutes); | |
| 419 | ||
| 59b6fb2 | 420 | // Notifications |
| 3ef4c9d | 421 | app.route("/", notificationRoutes); |
| 422 | ||
| 79136bb | 423 | // Repo settings (description, visibility, delete) |
| 424 | app.route("/", repoSettings); | |
| 425 | ||
| 23d1a81 | 426 | // Repo collaborators (add/list/remove) |
| 427 | app.route("/", collaboratorRoutes); | |
| 428 | ||
| 04f6b7f | 429 | // Team-based repo collaborators (invite a whole team) |
| 430 | app.route("/", teamCollaboratorRoutes); | |
| 431 | ||
| 432 | // Collaborator invite accept flow (token-based) | |
| 433 | app.route("/", invitesRoutes); | |
| 434 | ||
| 435 | // Real-time SSE endpoint (topic-based live updates) | |
| 436 | app.route("/", liveEventsRoutes); | |
| 437 | ||
| 3c03977 | 438 | // PR live co-editing — presence + cursors + content sync via SSE. |
| 439 | app.route("/", prLiveRoutes); | |
| 440 | ||
| c81ab7a | 441 | // Webhooks management |
| 442 | app.route("/", webhookRoutes); | |
| 443 | ||
| 79136bb | 444 | // Compare view (branch diffs) |
| 445 | app.route("/", compareRoutes); | |
| 446 | ||
| 447 | // Issue tracker | |
| 448 | app.route("/", issueRoutes); | |
| 449 | ||
| 0074234 | 450 | // Pull requests |
| 451 | app.route("/", pullRoutes); | |
| 79ed944 | 452 | // PR sandboxes — runnable per-PR environments. Migration 0067. |
| 453 | app.route("/", prSandboxRoutes); | |
| 0074234 | 454 | |
| c81ab7a | 455 | // Fork |
| 456 | app.route("/", forkRoutes); | |
| 457 | ||
| 0074234 | 458 | // Web file editor |
| 459 | app.route("/", editorRoutes); | |
| 460 | ||
| 43de941 | 461 | // Contributors |
| 462 | app.route("/", contributorRoutes); | |
| 463 | ||
| 699e5c7 | 464 | // Health liveness + metrics endpoints |
| 2c34075 | 465 | app.route("/", healthRoutes); |
| 466 | ||
| f295f78 | 467 | // Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md) |
| 468 | app.route("/api/platform-status", platformStatus); | |
| 469 | ||
| 52ad8b1 | 470 | // Block L4 — Public stats counters (powers landing-page social proof) |
| 471 | app.route("/", publicStatsRoutes); | |
| 472 | ||
| 473 | // Block L3 — Live /demo page + /api/v2/demo/* endpoints | |
| 474 | app.route("/", demoRoutes); | |
| 475 | ||
| 2316be6 | 476 | // Public /status — human-readable platform health page |
| 477 | app.route("/", statusRoutes); | |
| 478 | ||
| b1be050 | 479 | // BLOCK S4 — Site-admin synthetic-monitor dashboard (/admin/status). |
| 480 | // Mounted near the public status route so the two surfaces are visible | |
| 481 | // side-by-side; routes are gated by isSiteAdmin internally. | |
| 482 | app.route("/", adminStatusRoutes); | |
| 483 | ||
| 80bed05 | 484 | // /help — quickstart + API cheatsheet |
| 485 | app.route("/", helpRoutes); | |
| 486 | ||
| 5f2e749 | 487 | // L8 — public /pricing page (free-tier polish). Mounted BEFORE marketing |
| 488 | // so the new editorial pricing layout wins the route; the legacy marketing | |
| 489 | // pricing remains as a safety net but is shadowed at the router. | |
| 490 | app.route("/", pricingRoutes); | |
| 491 | ||
| b0148e9 | 492 | // /pricing, /features, /about — marketing surface |
| 493 | app.route("/", marketingRoutes); | |
| 494 | ||
| 5618f9a | 495 | // SEO: robots.txt + sitemap.xml |
| 496 | app.route("/", seoRoutes); | |
| 497 | ||
| 05cdb85 | 498 | // /api/version — live build SHA + uptime; client poller uses this to |
| 499 | // surface 'New version available — reload' banners on deploy. | |
| 500 | app.route("/", versionRoutes); | |
| 501 | ||
| 699e5c7 | 502 | // Health dashboard (per-repo health page) |
| 503 | app.route("/", healthDashboardRoutes); | |
| 504 | ||
| 9dd96b9 | 505 | // Block R1 — site-admin operations console. MUST be mounted BEFORE |
| 506 | // insightRoutes because its POST `/:owner/:repo/rollback` catch-all would | |
| 507 | // otherwise intercept `/admin/ops/rollback` (matching :owner=admin :repo=ops). | |
| 508 | app.route("/", adminOpsRoutes); | |
| f2c00b4 | 509 | // BLOCK W — Self-host status + bootstrap dashboard. |
| 510 | app.route("/", adminSelfHostRoutes); | |
| 826eccf | 511 | // BLOCK X — AI health-scan diagnose page (/admin/diagnose). |
| 512 | app.route("/", adminDiagnoseRoutes); | |
| 9dd96b9 | 513 | |
| 16b325c | 514 | // Insights (time-travel, dependencies, rollback) |
| 515 | app.route("/", insightRoutes); | |
| 516 | ||
| f1ab587 | 517 | // Command center dashboard |
| 518 | app.route("/", dashboardRoutes); | |
| 519 | ||
| 36b4cbd | 520 | // Legal pages (terms, privacy, AUP) |
| 521 | app.route("/", legalRoutes); | |
| 4b66018 | 522 | // Long-form legal sub-pages — /legal/{terms,privacy,acceptable-use,dmca}. |
| 523 | // The main `legal.tsx` serves the short canonical paths (/terms, /privacy, | |
| 524 | // /acceptable-use); these are the formal versions that the legal pages | |
| 525 | // internally link to each other. | |
| 526 | app.route("/", legalTermsRoutes); | |
| 527 | app.route("/", legalPrivacyRoutes); | |
| 528 | app.route("/", legalAcceptableUseRoutes); | |
| 529 | app.route("/", legalDmcaRoutes); | |
| 36b4cbd | 530 | |
| bdbd0de | 531 | // GitHub import / migration |
| 532 | app.route("/", importRoutes); | |
| 14c3cc8 | 533 | app.route("/", importBulkRoutes); |
| f390cfa | 534 | app.route("/", importSecretsRoutes); |
| 14c3cc8 | 535 | app.route("/", migrationRoutes); |
| 536 | ||
| 537 | // Spec-to-PR (experimental AI-generated draft PRs) | |
| 538 | app.route("/", specsRoutes); | |
| 23d0abf | 539 | app.route("/", refactorRoutes); |
| bdbd0de | 540 | |
| c81ab7a | 541 | // Explore page |
| 542 | app.route("/", exploreRoutes); | |
| 543 | ||
| 59b6fb2 | 544 | // Onboarding |
| 545 | app.route("/", onboardingRoutes); | |
| 546 | ||
| 0316dbb | 547 | // Admin + feature routes |
| 548 | app.route("/", adminRoutes); | |
| 509c376 | 549 | app.route("/", adminIntegrationsRoutes); |
| 79ed944 | 550 | app.route("/", adminAdvancementRoutes); |
| f764c07 | 551 | app.route("/", adminDeploysRoutes); |
| 552 | app.route("/", adminDeploysPageRoutes); | |
| 9dd96b9 | 553 | // Note: adminOpsRoutes is mounted earlier (before insightRoutes) — see comment above. |
| 0316dbb | 554 | app.route("/", advisoriesRoutes); |
| 555 | app.route("/", aiChangelogRoutes); | |
| 556 | app.route("/", aiExplainRoutes); | |
| 557 | app.route("/", aiTestsRoutes); | |
| 558 | app.route("/", askRoutes); | |
| 38d31d3 | 559 | app.route("/", repoChatRoutes); |
| 0316dbb | 560 | app.route("/", billingRoutes); |
| 8809b87 | 561 | app.route("/", billingUsageRoutes); |
| 6778ad2 | 562 | app.route("/", stripeWebhookRoutes); |
| 0316dbb | 563 | app.route("/", codeScanningRoutes); |
| 564 | app.route("/", commitStatusesRoutes); | |
| 565 | app.route("/", copilotRoutes); | |
| 566 | app.route("/", depUpdaterRoutes); | |
| 567 | app.route("/", depsRoutes); | |
| 568 | app.route("/", discussionsRoutes); | |
| 569 | app.route("/", environmentsRoutes); | |
| 4bbacbe | 570 | app.route("/", previewsRoutes); |
| 79ed944 | 571 | app.route("/", docsTrackingRoutes); |
| 0316dbb | 572 | app.route("/", followsRoutes); |
| 573 | app.route("/", gatesRoutes); | |
| 574 | app.route("/", gistsRoutes); | |
| 575 | app.route("/", graphqlRoutes); | |
| 2c2163e | 576 | app.route("/", mcpRoutes); |
| 0316dbb | 577 | app.route("/", marketplaceRoutes); |
| 578 | app.route("/", mergeQueueRoutes); | |
| 579 | app.route("/", mirrorsRoutes); | |
| 580 | app.route("/", orgInsightsRoutes); | |
| 581 | app.route("/", packagesRoutes); | |
| 582 | app.route("/", packagesApiRoutes); | |
| 583 | app.route("/", pagesRoutes); | |
| 584 | app.route("/", projectsRoutes); | |
| 585 | app.route("/", protectedTagsRoutes); | |
| 586 | app.route("/", pwaRoutes); | |
| 46d6165 | 587 | app.route("/", installRoutes); |
| cd4f63b | 588 | // BLOCK Q1 — /gluecron.dxt download (Claude Desktop one-click extension) |
| 589 | app.route("/", dxtRoutes); | |
| 662ce86 | 590 | // Connect Claude — user-facing one-click MCP setup (/connect/claude). Mounted |
| 591 | // next to the other one-click flows (install.sh + .dxt) for surface symmetry. | |
| 592 | app.route("/", connectClaudeRoutes); | |
| 0316dbb | 593 | app.route("/", releasesRoutes); |
| 594 | app.route("/", requiredChecksRoutes); | |
| 595 | app.route("/", rulesetsRoutes); | |
| 596 | app.route("/", searchRoutes); | |
| 597 | app.route("/", semanticSearchRoutes); | |
| 598 | app.route("/", signingKeysRoutes); | |
| 599 | app.route("/", sponsorsRoutes); | |
| 600 | app.route("/", ssoRoutes); | |
| 46d6165 | 601 | app.route("/", githubOauthRoutes); |
| 582cdac | 602 | app.route("/", googleOauthRoutes); |
| 0316dbb | 603 | app.route("/", symbolsRoutes); |
| 604 | app.route("/", templatesRoutes); | |
| 605 | app.route("/", trafficRoutes); | |
| 606 | app.route("/", wikisRoutes); | |
| 607 | app.route("/", workflowsRoutes); | |
| 5ff9cc2 | 608 | app.route("/", workflowArtifactsRoutes); |
| 609 | app.route("/", workflowSecretsRoutes); | |
| 46d6165 | 610 | app.route("/", sleepModeRoutes); |
| 52ad8b1 | 611 | app.route("/", vsGithubRoutes); |
| 0316dbb | 612 | |
| 45f3b73 | 613 | // Voice-to-PR — phone-first dictation → spec or issue |
| 614 | app.route("/", voiceRoutes); | |
| 615 | ||
| cd4f63b | 616 | // Block Q3 — Anonymous playground (`/play`, `/play/claim`). Mounted |
| 617 | // before the web catch-all so the bare `/play` literal wins over the | |
| 618 | // `/:owner` user-profile route. | |
| 619 | app.route("/", playgroundRoutes); | |
| 620 | ||
| 79136bb | 621 | // Web UI (catch-all, must be last) |
| 622 | app.route("/", webRoutes); | |
| 623 | ||
| c63b860 | 624 | // Global 404 — BLOCK O2 routes the shared `NotFoundPage` view so |
| 625 | // the markup stays consistent with /500 and the admin /403 page. | |
| 79136bb | 626 | app.notFound((c) => { |
| 36cc17a | 627 | const user = c.get("user") ?? null; |
| 79136bb | 628 | return c.html( |
| c63b860 | 629 | <NotFoundPage user={user} method={c.req.method} path={c.req.path} />, |
| 79136bb | 630 | 404 |
| 631 | ); | |
| 632 | }); | |
| 633 | ||
| c63b860 | 634 | // Global error handler — BLOCK O2 uses the shared `ServerErrorPage` |
| 635 | // view. Trace block only shown outside production. | |
| 79136bb | 636 | app.onError((err, c) => { |
| 80bed05 | 637 | reportError(err, { |
| 638 | requestId: c.get("requestId"), | |
| 639 | path: c.req.path, | |
| 640 | method: c.req.method, | |
| 641 | }); | |
| c63b860 | 642 | // Prefer the inbound `x-request-id` header (LB-supplied) and fall |
| 643 | // back to the context value set by request-context middleware. | |
| 644 | const requestId = | |
| 645 | c.req.header("x-request-id") || | |
| 646 | ((c.get("requestId" as never) as string | undefined) ?? undefined); | |
| 36cc17a | 647 | const user = c.get("user") ?? null; |
| c63b860 | 648 | const trace = |
| 649 | process.env.NODE_ENV !== "production" && err && err.message | |
| 650 | ? err.message | |
| 651 | : undefined; | |
| 79136bb | 652 | return c.html( |
| c63b860 | 653 | <ServerErrorPage user={user} requestId={requestId} trace={trace} />, |
| 79136bb | 654 | 500 |
| 655 | ); | |
| 656 | }); | |
| 657 | ||
| 658 | export default app; |