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"; |
| 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"; | |
| cc34156 | 19 | import digestRoutes from "./routes/digest"; |
| e9aa4d8 | 20 | import activityRoutes from "./routes/activity"; |
| 79136bb | 21 | import authRoutes from "./routes/auth"; |
| c63b860 | 22 | import passwordResetRoutes from "./routes/password-reset"; |
| 23 | import emailVerificationRoutes from "./routes/email-verification"; | |
| cd4f63b | 24 | import magicLinkRoutes from "./routes/magic-link"; |
| 79136bb | 25 | import settingsRoutes from "./routes/settings"; |
| 7298a17 | 26 | import settings2faRoutes from "./routes/settings-2fa"; |
| e75eddc | 27 | import settingsAgentsRoutes from "./routes/settings-agents"; |
| 1d4ff60 | 28 | import settingsIntegrationsRoutes from "./routes/settings-integrations"; |
| 29 | import integrationsChatRoutes from "./routes/integrations-chat"; | |
| e75eddc | 30 | import agentsRoutes from "./routes/agents"; |
| ef3fd93 | 31 | import agentPipelinesRoutes from "./routes/agent-pipelines"; |
| 79136bb | 32 | import issueRoutes from "./routes/issues"; |
| 85c4e13 | 33 | import milestonesRoutes from "./routes/milestones"; |
| f928118 | 34 | import shipAgentRoutes from "./routes/ship-agent"; |
| cb5a796 | 35 | import commentModerationRoutes from "./routes/comment-moderation"; |
| 79136bb | 36 | import repoSettings from "./routes/repo-settings"; |
| 479dcd9 | 37 | import automationSettingsRoutes from "./routes/automation-settings"; |
| 23d1a81 | 38 | import collaboratorRoutes from "./routes/collaborators"; |
| 04f6b7f | 39 | import teamCollaboratorRoutes from "./routes/team-collaborators"; |
| 40 | import invitesRoutes from "./routes/invites"; | |
| 41 | import liveEventsRoutes from "./routes/live-events"; | |
| 3c03977 | 42 | import prLiveRoutes from "./routes/pr-live"; |
| 79136bb | 43 | import compareRoutes from "./routes/compare"; |
| 0074234 | 44 | import pullRoutes from "./routes/pulls"; |
| 79ed944 | 45 | import prSandboxRoutes from "./routes/pr-sandbox"; |
| 9b3a183 | 46 | import devEnvRoutes from "./routes/dev-env"; |
| 0074234 | 47 | import editorRoutes from "./routes/editor"; |
| 6f2809f | 48 | import aiEditorRoutes from "./routes/ai-editor"; |
| c81ab7a | 49 | import forkRoutes from "./routes/fork"; |
| 50 | import webhookRoutes from "./routes/webhooks"; | |
| 51 | import exploreRoutes from "./routes/explore"; | |
| 52 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 53 | import contributorRoutes from "./routes/contributors"; |
| 699e5c7 | 54 | import healthRoutes from "./routes/health-probe"; |
| 55 | import healthDashboardRoutes from "./routes/health"; | |
| 2316be6 | 56 | import statusRoutes from "./routes/status"; |
| b1be050 | 57 | import adminStatusRoutes from "./routes/admin-status"; |
| 80bed05 | 58 | import helpRoutes from "./routes/help"; |
| e1fc7db | 59 | import changelogRoutes from "./routes/changelog"; |
| e0e4219 | 60 | import docsRoutes from "./routes/docs"; |
| b0148e9 | 61 | import marketingRoutes from "./routes/marketing"; |
| 5f2e749 | 62 | import pricingRoutes from "./routes/pricing"; |
| 9f29b65 | 63 | import enterpriseRoutes from "./routes/enterprise"; |
| 5618f9a | 64 | import seoRoutes from "./routes/seo"; |
| 05cdb85 | 65 | import versionRoutes from "./routes/version"; |
| f295f78 | 66 | import { platformStatus } from "./routes/platform-status"; |
| 52ad8b1 | 67 | import publicStatsRoutes from "./routes/public-stats"; |
| 68 | import demoRoutes from "./routes/demo"; | |
| 16b325c | 69 | import insightRoutes from "./routes/insights"; |
| 8286942 | 70 | import engineeringInsightsRoutes from "./routes/engineering-insights"; |
| 8d1483c | 71 | import doraRoutes from "./routes/dora"; |
| f1ab587 | 72 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 73 | import legalRoutes from "./routes/legal"; |
| 4b66018 | 74 | import legalDmcaRoutes from "./routes/legal/dmca"; |
| 75 | import legalTermsRoutes from "./routes/legal/terms"; | |
| 76 | import legalPrivacyRoutes from "./routes/legal/privacy"; | |
| 77 | import legalAcceptableUseRoutes from "./routes/legal/acceptable-use"; | |
| bdbd0de | 78 | import importRoutes from "./routes/import"; |
| 14c3cc8 | 79 | import importBulkRoutes from "./routes/import-bulk"; |
| f390cfa | 80 | import importSecretsRoutes from "./routes/import-secrets"; |
| bb2dea9 | 81 | import actionsImporterRoutes from "./routes/actions-importer"; |
| 14c3cc8 | 82 | import migrationRoutes from "./routes/migrations"; |
| ba23fe2 | 83 | import migrationAssistantRoutes from "./routes/migration-assistant"; |
| 9a8b8de | 84 | import migrateRoutes from "./routes/migrate"; |
| 14c3cc8 | 85 | import specsRoutes from "./routes/specs"; |
| 23d0abf | 86 | import refactorRoutes from "./routes/refactors"; |
| b665cac | 87 | import codebaseMigratorRoutes from "./routes/codebase-migrator"; |
| 79136bb | 88 | import webRoutes from "./routes/web"; |
| 0316dbb | 89 | import hookRoutes from "./routes/hooks"; |
| 90 | import eventsRoutes from "./routes/events"; | |
| 91 | import passkeyRoutes from "./routes/passkeys"; | |
| 92 | import oauthRoutes from "./routes/oauth"; | |
| 369ad65 | 93 | import wellKnownRoutes from "./routes/well-known"; |
| 0316dbb | 94 | import developerAppsRoutes from "./routes/developer-apps"; |
| 95 | import themeRoutes from "./routes/theme"; | |
| 96 | import auditRoutes from "./routes/audit"; | |
| 97 | import reactionRoutes from "./routes/reactions"; | |
| 98 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 99 | import deploymentRoutes from "./routes/deployments"; | |
| 2c61840 | 100 | import pipelineRoutes from "./routes/pipeline"; |
| 0316dbb | 101 | import orgRoutes from "./routes/orgs"; |
| 102 | import notificationRoutes from "./routes/notifications"; | |
| 103 | import onboardingRoutes from "./routes/onboarding"; | |
| 104 | import adminRoutes from "./routes/admin"; | |
| 7293c67 | 105 | import adminDeletionsRoutes from "./routes/admin-deletions"; |
| 106 | import adminStripeRoutes from "./routes/admin-stripe"; | |
| f764c07 | 107 | import adminDeploysRoutes from "./routes/admin-deploys"; |
| 108 | import adminDeploysPageRoutes from "./routes/admin-deploys-page"; | |
| 783dd46 | 109 | import adminServerTargetsRoutes from "./routes/admin-server-targets"; |
| 9aaa128 | 110 | import deployTargetsRoutes from "./routes/deploy-targets"; |
| 90c7531 | 111 | import claudeWebRoutes from "./routes/claude-web"; |
| 9dd96b9 | 112 | import adminOpsRoutes from "./routes/admin-ops"; |
| f2c00b4 | 113 | import adminSelfHostRoutes from "./routes/admin-self-host"; |
| 826eccf | 114 | import adminDiagnoseRoutes from "./routes/admin-diagnose"; |
| f9814d2 | 115 | import adminCommandRoutes from "./routes/admin-command"; |
| 509c376 | 116 | import adminIntegrationsRoutes from "./routes/admin-integrations"; |
| bc519ae | 117 | import adminEnvHealthRoutes from "./routes/admin-env-health"; |
| 79ed944 | 118 | import adminAdvancementRoutes from "./routes/admin-advancement"; |
| ba9e143 | 119 | import adminSecurityRoutes from "./routes/admin-security"; |
| 120 | import settingsSessionsRoutes from "./routes/settings-sessions"; | |
| 0316dbb | 121 | import advisoriesRoutes from "./routes/advisories"; |
| 122 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 0a69faa | 123 | import explainRoutes from "./routes/explain"; |
| 0316dbb | 124 | import aiExplainRoutes from "./routes/ai-explain"; |
| 2be65d0 | 125 | import archaeologyRoutes from "./routes/ai-archaeology"; |
| 0316dbb | 126 | import aiTestsRoutes from "./routes/ai-tests"; |
| 127 | import askRoutes from "./routes/ask"; | |
| 38d31d3 | 128 | import repoChatRoutes from "./routes/repo-chat"; |
| ee7e577 | 129 | import personalChatRoutes from "./routes/personal-chat"; |
| 0316dbb | 130 | import billingRoutes from "./routes/billing"; |
| 8809b87 | 131 | import billingUsageRoutes from "./routes/billing-usage"; |
| 6778ad2 | 132 | import stripeWebhookRoutes from "./routes/stripe-webhook"; |
| 0316dbb | 133 | import codeScanningRoutes from "./routes/code-scanning"; |
| da3fc18 | 134 | import securityRoutes from "./routes/security"; |
| 0316dbb | 135 | import commitStatusesRoutes from "./routes/commit-statuses"; |
| 136 | import copilotRoutes from "./routes/copilot"; | |
| f5d020f | 137 | import { pairProgrammerRoutes } from "./routes/pair-programmer"; |
| 0316dbb | 138 | import depUpdaterRoutes from "./routes/dep-updater"; |
| 139 | import depsRoutes from "./routes/deps"; | |
| 140 | import discussionsRoutes from "./routes/discussions"; | |
| 141 | import environmentsRoutes from "./routes/environments"; | |
| 4bbacbe | 142 | import previewsRoutes from "./routes/previews"; |
| 79ed944 | 143 | import docsTrackingRoutes from "./routes/docs-tracking"; |
| 0316dbb | 144 | import followsRoutes from "./routes/follows"; |
| 145 | import gatesRoutes from "./routes/gates"; | |
| 146 | import gistsRoutes from "./routes/gists"; | |
| 147 | import graphqlRoutes from "./routes/graphql"; | |
| 2c2163e | 148 | import mcpRoutes from "./routes/mcp"; |
| 0316dbb | 149 | import marketplaceRoutes from "./routes/marketplace"; |
| 5ca514a | 150 | import marketplaceAgentsRoutes from "./routes/marketplace-agents"; |
| 0316dbb | 151 | import mergeQueueRoutes from "./routes/merge-queue"; |
| 152 | import mirrorsRoutes from "./routes/mirrors"; | |
| 153 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 2be65d0 | 154 | import orgHealthRoutes from "./routes/org-health"; |
| 0316dbb | 155 | import packagesRoutes from "./routes/packages"; |
| 156 | import packagesApiRoutes from "./routes/packages-api"; | |
| 845fd8a | 157 | import ociRegistryRoutes from "./routes/oci-registry"; |
| 0316dbb | 158 | import pagesRoutes from "./routes/pages"; |
| 159 | import projectsRoutes from "./routes/projects"; | |
| 160 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 161 | import pwaRoutes from "./routes/pwa"; | |
| 46d6165 | 162 | import installRoutes from "./routes/install"; |
| cd4f63b | 163 | import dxtRoutes from "./routes/dxt"; |
| 662ce86 | 164 | import connectClaudeRoutes from "./routes/connect-claude"; |
| ebbb527 | 165 | import claudeDeployRoutes from "./routes/claude-deploy"; |
| f5b9ef5 | 166 | import claudeIntegration from "./routes/claude-integration"; |
| 167 | import connectRoutes from "./routes/connect"; | |
| 05ab9b1 | 168 | import pushWatchRoutes from "./routes/push-watch"; |
| 169 | import orgSecretsRoutes from "./routes/org-secrets"; | |
| 0316dbb | 170 | import releasesRoutes from "./routes/releases"; |
| 171 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 172 | import rulesetsRoutes from "./routes/rulesets"; | |
| 173 | import searchRoutes from "./routes/search"; | |
| 174 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 77cf834 | 175 | import nlSearchRoutes from "./routes/nl-search"; |
| 0316dbb | 176 | import signingKeysRoutes from "./routes/signing-keys"; |
| 177 | import sponsorsRoutes from "./routes/sponsors"; | |
| 178 | import ssoRoutes from "./routes/sso"; | |
| 3a845e4 | 179 | import samlSsoRoutes from "./routes/saml-sso"; |
| 180 | import scimRoutes from "./routes/scim"; | |
| 181 | import orgSsoSettingsRoutes from "./routes/org-sso-settings"; | |
| 46d6165 | 182 | import githubOauthRoutes from "./routes/github-oauth"; |
| 582cdac | 183 | import googleOauthRoutes from "./routes/google-oauth"; |
| 0316dbb | 184 | import symbolsRoutes from "./routes/symbols"; |
| 185 | import templatesRoutes from "./routes/templates"; | |
| 186 | import trafficRoutes from "./routes/traffic"; | |
| 187 | import wikisRoutes from "./routes/wikis"; | |
| 188 | import workflowsRoutes from "./routes/workflows"; | |
| 5ff9cc2 | 189 | import workflowArtifactsRoutes from "./routes/workflow-artifacts"; |
| 190 | import workflowSecretsRoutes from "./routes/workflow-secrets"; | |
| 46d6165 | 191 | import sleepModeRoutes from "./routes/sleep-mode"; |
| 56801e1 | 192 | import standupRoutes from "./routes/standups"; |
| 52ad8b1 | 193 | import vsGithubRoutes from "./routes/vs-github"; |
| 45f3b73 | 194 | import voiceRoutes from "./routes/voice-to-pr"; |
| 3122762 | 195 | import blogRoutes from "./routes/blog"; |
| cd4f63b | 196 | import playgroundRoutes from "./routes/playground"; |
| a2b3e99 | 197 | import crossRepoSearchRoutes from "./routes/cross-repo-search"; |
| 198 | import pushNotifRoutes from "./routes/push-notifications"; | |
| 9fbe6cd | 199 | import velocityRoutes from "./routes/velocity"; |
| 200 | import { staleBranchRoutes } from "./routes/stale-branches"; | |
| 22f43f3 | 201 | import pulseRoutes from "./routes/pulse"; |
| 74d8c4d | 202 | import healthScoreRoutes from "./routes/health-score"; |
| 77cf834 | 203 | import repoHealthRoutes from "./routes/repo-health"; |
| 74d8c4d | 204 | import hotFilesRoutes from "./routes/hot-files"; |
| bcc4020 | 205 | import debtMapRoutes from "./routes/debt-map"; |
| 1d6db4d | 206 | import busFactorRoutes from "./routes/bus-factor"; |
| 2be65d0 | 207 | import testGapsRoutes from "./routes/test-gaps"; |
| f5d020f | 208 | import crossRepoImpactRoutes from "./routes/cross-repo-impact"; |
| adf5e18 | 209 | import developerProgramRoutes from "./routes/developer-program"; |
| 891efbe | 210 | import shareRoutes from "./routes/share"; |
| 70e3293 | 211 | import incidentHookRoutes from "./routes/incident-hooks"; |
| 77cf834 | 212 | import workspaceRoutes from "./routes/ai-workspace"; |
| 2c61840 | 213 | import workspaceHubRoutes from "./routes/workspace-hub"; |
| 4d4bd4b | 214 | import { apiRateLimit, authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 59b6fb2 | 215 | import { csrfToken, csrfProtect } from "./middleware/csrf"; |
| f5b9ef5 | 216 | import { noCache } from "./middleware/no-cache"; |
| 79136bb | 217 | |
| 2316901 | 218 | import type { AuthEnv } from "./middleware/auth"; |
| bf19c50 | 219 | import { softAuth } from "./middleware/auth"; |
| 2316901 | 220 | |
| 221 | const app = new Hono<AuthEnv>(); | |
| 79136bb | 222 | |
| 3ef4c9d | 223 | // Request context (request ID, start time) runs before everything else |
| 224 | app.use("*", requestContext); | |
| 05b973e | 225 | // Middleware — compression first (wraps all responses) |
| 226 | app.use("*", compress()); | |
| f1ffd50 | 227 | |
| 228 | // ETag middleware — returns 304 Not Modified on unchanged responses. | |
| 229 | // Saves ~95% bandwidth on repeat visits. Skipped on git protocol + | |
| 230 | // SSE + the API surface where it would interfere with streaming. | |
| 231 | app.use("*", async (c, next) => { | |
| 232 | const p = c.req.path; | |
| 233 | if ( | |
| 234 | p.includes(".git/") || | |
| 235 | p.startsWith("/live-events") || | |
| 236 | p.startsWith("/api/events/deploy") || | |
| 3c03977 | 237 | p.startsWith("/admin/status") || |
| 238 | // PR live co-editing SSE stream — never etag streaming responses. | |
| 239 | /^\/api\/v2\/pulls\/[^/]+\/live(\/|$)/.test(p) | |
| f1ffd50 | 240 | ) { |
| 241 | return next(); | |
| 242 | } | |
| 243 | return etag()(c, next); | |
| 244 | }); | |
| 245 | ||
| 246 | // Cache-Control middleware — sets sensible defaults on public, anonymous | |
| 9ecf5a4 | 247 | // requests. Vapron (when wired as our edge layer) and downstream |
| f1ffd50 | 248 | // browsers will honor these. Auth'd users get private,no-store |
| 249 | // automatically — we never cache responses tied to a session. | |
| 250 | app.use("*", async (c, next) => { | |
| 251 | await next(); | |
| 252 | // Don't overwrite explicit headers set by route handlers — BUT the | |
| 253 | // ETag middleware unconditionally sets "private, no-cache, must- | |
| 254 | // revalidate" so we have to treat that specific value as "no | |
| 255 | // policy chosen yet" and apply ours. Any route that explicitly set | |
| 256 | // a different cache-control wins. | |
| 257 | const existing = c.res.headers.get("cache-control"); | |
| 258 | const etagDefault = | |
| 259 | existing === "private, no-cache, must-revalidate" || | |
| 260 | existing === "no-cache"; | |
| 261 | if (existing && !etagDefault) return; | |
| 262 | // Anything past auth: private + no-store (avoid leaking session | |
| 263 | // content into shared caches). softAuth runs before this on the | |
| 264 | // request, but the response side is what we're stamping. | |
| 265 | const hasSession = c.req.header("cookie")?.includes("session=") ?? false; | |
| 266 | const p = c.req.path; | |
| 267 | // Always private for known-authed paths regardless of cookie. | |
| 268 | if ( | |
| 269 | p.startsWith("/admin") || | |
| 270 | p.startsWith("/settings") || | |
| 271 | p.startsWith("/dashboard") || | |
| 272 | p.startsWith("/notifications") || | |
| 273 | p.startsWith("/connect/") || | |
| 274 | hasSession | |
| 275 | ) { | |
| 276 | c.res.headers.set("cache-control", "private, no-store"); | |
| 277 | return; | |
| 278 | } | |
| 279 | // Public marketing surfaces — short edge cache, longer browser cache, | |
| 280 | // stale-while-revalidate so the user never waits on a stale fetch. | |
| 281 | const isMarketing = | |
| 282 | p === "/" || | |
| 283 | p === "/features" || | |
| 284 | p === "/pricing" || | |
| 285 | p === "/about" || | |
| 286 | p === "/vs-github" || | |
| 287 | p === "/explore" || | |
| 288 | p === "/help" || | |
| 289 | p === "/changelog" || | |
| 9f29b65 | 290 | p === "/enterprise" || |
| f1ffd50 | 291 | p.startsWith("/legal/") || |
| 292 | p === "/terms" || | |
| 293 | p === "/privacy" || | |
| 294 | p === "/acceptable-use" || | |
| 295 | p.startsWith("/docs/"); | |
| 296 | if (isMarketing) { | |
| 297 | c.res.headers.set( | |
| 298 | "cache-control", | |
| 299 | "public, max-age=60, s-maxage=300, stale-while-revalidate=86400" | |
| 300 | ); | |
| 301 | return; | |
| 302 | } | |
| 303 | // Public repo browse pages — cache aggressively. Edge invalidates | |
| 9ecf5a4 | 304 | // on push via the post-receive hook (future Vapron surge purge). |
| f1ffd50 | 305 | if (/^\/[^/]+\/[^/]+(\/.*)?$/.test(p) && c.req.method === "GET") { |
| 306 | c.res.headers.set( | |
| 307 | "cache-control", | |
| 308 | "public, max-age=30, s-maxage=120, stale-while-revalidate=600" | |
| 309 | ); | |
| 310 | return; | |
| 311 | } | |
| 312 | // Default: don't cache anything we haven't explicitly opted in. | |
| 313 | c.res.headers.set("cache-control", "private, no-store"); | |
| 314 | }); | |
| 05b973e | 315 | // Logger only on non-git routes to avoid overhead on clone/push |
| 316 | app.use("*", async (c, next) => { | |
| 317 | if (c.req.path.includes(".git/")) return next(); | |
| 318 | return logger()(c, next); | |
| 319 | }); | |
| 79136bb | 320 | app.use("/api/*", cors()); |
| bf19c50 | 321 | // Global softAuth — populates c.get("user") for every downstream middleware |
| 322 | // + route. This was previously per-route, which meant rate-limit middleware | |
| 323 | // (and anything else inspecting auth state) always saw a null user. Keep | |
| 324 | // individual routes free to add requireAuth on top for hard gating; this | |
| 325 | // just establishes the user object cheaply. | |
| 326 | app.use("*", softAuth); | |
| 290ea77 | 327 | |
| 36cc17a | 328 | // Force-revalidate HTML on every request — kills browser cache holding stale |
| 290ea77 | 329 | // pre-redesign markup. JSON / static assets keep their own cache rules; only |
| 330 | // text/html responses get the no-cache stamp. Without this, every push to | |
| 331 | // main left users staring at cached 80s-looking pages from before the design | |
| 332 | // landed. | |
| 36cc17a | 333 | // |
| 334 | // We deliberately use `private, no-cache, must-revalidate` rather than | |
| 335 | // `no-store`. `no-store` disables Safari/Chrome's back-forward cache (bfcache), | |
| 336 | // which makes every Back/Forward press a cold server round-trip — that | |
| 337 | // contributed to the "every nav feels like a fresh login" UX complaint. | |
| 338 | // `no-cache` still revalidates on direct fetch but lets bfcache hold the | |
| 339 | // page in memory between navigations. | |
| 290ea77 | 340 | app.use("*", async (c, next) => { |
| 341 | await next(); | |
| 342 | const ct = c.res.headers.get("content-type") || ""; | |
| 343 | if (ct.startsWith("text/html")) { | |
| 36cc17a | 344 | c.header("cache-control", "private, no-cache, must-revalidate"); |
| 290ea77 | 345 | } |
| 346 | }); | |
| 826eccf | 347 | // Rate-limit API + auth endpoints. |
| 348 | // | |
| a41e675 | 349 | // `/api/*`: 1000/min per IP — generous so an admin clicking around the |
| 350 | // operator console (or a CDN/proxy concentrating multiple users behind one | |
| 351 | // IP) doesn't hit the wall. Bot-resistant headroom comes from the auth | |
| 352 | // rate limits below, not this one. | |
| 353 | // | |
| 354 | // `authedMultiplier` is set but only fires when an upstream middleware has | |
| 355 | // already populated c.get("user") — most app.use() chains apply softAuth | |
| 356 | // per-route, so the multiplier is best-effort. Keep the anonymous base | |
| 357 | // high enough that humans never feel it. | |
| 358 | // | |
| 359 | // Skip-paths: dashboard plumbing endpoints that the layout polls on a | |
| 360 | // fixed cadence and that we don't want consuming any bucket: | |
| 361 | // /api/version — layout polls every 15s | |
| 826eccf | 362 | // /api/notifications/count — nav bell unread-count fetcher |
| 363 | // /pwa/vapid-public-key — fetched once per push-notification opt-in | |
| 364 | app.use( | |
| 365 | "/api/*", | |
| a41e675 | 366 | rateLimit(1000, 60_000, "api", { |
| 826eccf | 367 | authedMultiplier: 4, |
| 368 | skipPaths: ["/api/version", "/api/notifications/count", "/pwa/vapid-public-key"], | |
| 369 | }) | |
| 370 | ); | |
| 0316dbb | 371 | app.use("/login", rateLimit(20, 60_000, "login")); |
| 372 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| c63b860 | 373 | // BLOCK P1 — throttle forgot-password to deter enumeration + mail spam. |
| 374 | app.use("/forgot-password", rateLimit(5, 60_000, "forgot-password")); | |
| cd4f63b | 375 | // BLOCK Q2 — throttle magic-link sign-in for the same reason. |
| 376 | app.use("/login/magic", rateLimit(5, 60_000, "magic-link")); | |
| 79136bb | 377 | |
| 59b6fb2 | 378 | // CSRF protection — set token on all requests, validate on mutations |
| 379 | app.use("*", csrfToken); | |
| 380 | app.use("*", csrfProtect); | |
| 381 | ||
| 45e31d0 | 382 | // Rate limit auth routes |
| 383 | app.use("/login", authRateLimit); | |
| 384 | app.use("/register", authRateLimit); | |
| 385 | ||
| 59b6fb2 | 386 | // Rate limit git operations |
| 387 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 388 | ||
| 389 | // Rate limit search | |
| 390 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 391 | app.use("/explore", searchRateLimit); | |
| 79136bb | 392 | |
| 4d4bd4b | 393 | // Rate limit the v1 REST API and the MCP surface. api-v2 already applies its |
| 394 | // own apiRateLimit internally (this stacks harmlessly for /api/v2/*); v1 | |
| 395 | // (src/routes/api.ts) and /mcp had NO rate limiting at all despite /mcp | |
| 396 | // being the primary, anonymously-reachable AI-agent interface and able to | |
| 397 | // trigger expensive per-call work (e.g. gluecron_repo_health scans every | |
| 398 | // file in a repo). softAuth already runs on both, so the existing | |
| 399 | // authedMultiplier (4x for a signed-in caller) applies automatically. | |
| 400 | app.use("/api/*", apiRateLimit); | |
| 401 | app.use("/mcp", apiRateLimit); | |
| 402 | ||
| f5b9ef5 | 403 | // No-cache for HTML — ensures browsers and proxies never serve stale pages. |
| 404 | // The middleware only stamps text/html responses so static assets keep | |
| 405 | // their own cache policies unchanged. | |
| 406 | app.use("*", noCache); | |
| 407 | ||
| 79136bb | 408 | // Git Smart HTTP protocol routes (must be before web routes) |
| 409 | app.route("/", gitRoutes); | |
| 410 | ||
| 45e31d0 | 411 | // REST API v1 (legacy) |
| 79136bb | 412 | app.route("/", apiRoutes); |
| 413 | ||
| 52ad8b1 | 414 | // Block L3 — /demo + /api/v2/demo/* live demo endpoints. Mounted BEFORE |
| 415 | // apiV2Routes so the /api/v2/demo/* JSON endpoints win over the v2 base | |
| 416 | // router's catch-shape, and BEFORE adminRoutes so the live /demo page | |
| 417 | // wins over the legacy /demo redirect in src/routes/admin.tsx. | |
| 418 | app.route("/", demoRoutes); | |
| 419 | ||
| 0316dbb | 420 | // REST API v2 (basePath /api/v2) |
| 421 | app.route("/", apiV2Routes); | |
| 422 | ||
| e75eddc | 423 | // Agent multiplayer v1 — /api/v2/agents/* (sessions, leases, usage). |
| 424 | // Mounted alongside apiV2Routes (its own basePath, no path conflict). | |
| 425 | app.route("/", agentsRoutes); | |
| 426 | ||
| ef3fd93 | 427 | // Multi-agent pipeline UI — /:owner/:repo/agents (list, new, live view). |
| 428 | // Must be before webRoutes (the catch-all) so the /agents sub-paths are | |
| 429 | // resolved before the generic tree/blob route takes over. | |
| 430 | app.route("/", agentPipelinesRoutes); | |
| 431 | ||
| ad6d4ad | 432 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 433 | app.route("/", hookRoutes); | |
| 21f8dbd | 434 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 435 | |
| 45e31d0 | 436 | // API documentation |
| 437 | app.route("/", apiDocsRoutes); | |
| 4a80519 | 438 | app.route("/", buildAgentSpecRoutes); |
| a6ff0f2 | 439 | // PR command center — global PR dashboard with AI/GateTest/auto-merge signal |
| 440 | app.route("/", pullsDashboardRoutes); | |
| e9aa4d8 | 441 | // Issue command center — global issue dashboard with AI-triage + autopilot signal |
| 442 | app.route("/", issuesDashboardRoutes); | |
| 443 | // Personal activity timeline — every event across the user's repos, with | |
| 444 | // AI-driven events surfaced separately (the Gluecron differentiator). | |
| 445 | app.route("/", activityRoutes); | |
| 446 | // Unified inbox — mentions + review requests + CI failures + AI events in one timeline | |
| 447 | app.route("/", inboxRoutes); | |
| 56801e1 | 448 | // AI standup feed — daily / weekly Claude-generated team brief |
| 449 | app.route("/", standupRoutes); | |
| cc34156 | 450 | // Smart morning digest — AI-curated daily developer queue (/digest) |
| 451 | app.route("/", digestRoutes); | |
| 79136bb | 452 | |
| 453 | // Auth routes (register, login, logout) | |
| 454 | app.route("/", authRoutes); | |
| 455 | ||
| c63b860 | 456 | // BLOCK P1 — Password reset (forgot-password + reset-password) |
| 457 | app.route("/", passwordResetRoutes); | |
| 458 | ||
| 459 | // BLOCK P2 — Email verification (verify-email + resend) | |
| 460 | app.route("/", emailVerificationRoutes); | |
| 461 | ||
| cd4f63b | 462 | // BLOCK Q2 — Magic-link sign-in (/login/magic + callback) |
| 463 | app.route("/", magicLinkRoutes); | |
| 464 | ||
| 79136bb | 465 | // Settings routes (profile, SSH keys) |
| 466 | app.route("/", settingsRoutes); | |
| 467 | ||
| ba9e143 | 468 | // Session management (SOC 2 CC6.1 — /settings/sessions) |
| 469 | app.route("/", settingsSessionsRoutes); | |
| 470 | ||
| 7298a17 | 471 | // 2FA / TOTP settings (Block B4) |
| 472 | app.route("/", settings2faRoutes); | |
| 473 | ||
| e75eddc | 474 | // Agent multiplayer — /settings/agents management UI |
| 475 | app.route("/", settingsAgentsRoutes); | |
| 476 | ||
| 1d4ff60 | 477 | // Chat integrations — Slack / Discord / Teams (/settings/integrations |
| 478 | // + /api/v2/integrations/{slack,discord}/*). See src/lib/chat-bot.ts. | |
| 479 | app.route("/", settingsIntegrationsRoutes); | |
| 480 | app.route("/", integrationsChatRoutes); | |
| 481 | ||
| 2df1f8c | 482 | // WebAuthn / passkey routes (Block B5) |
| 483 | app.route("/", passkeyRoutes); | |
| 484 | ||
| 058d752 | 485 | // OAuth 2.0 provider (Block B6) |
| 486 | app.route("/", oauthRoutes); | |
| 487 | app.route("/", developerAppsRoutes); | |
| 369ad65 | 488 | // OAuth / agent discovery metadata (RFC 8414 + RFC 9728) — lets claude.ai, |
| 489 | // Cursor, Copilot, etc. auto-discover how to authenticate. | |
| 490 | app.route("/", wellKnownRoutes); | |
| 058d752 | 491 | |
| 6fc53bd | 492 | // Theme toggle (dark/light cookie) |
| 493 | app.route("/", themeRoutes); | |
| 494 | ||
| 495 | // Audit log UI | |
| 496 | app.route("/", auditRoutes); | |
| 497 | ||
| 498 | // Reactions API (issues, PRs, comments) | |
| 499 | app.route("/", reactionRoutes); | |
| 500 | ||
| 24cf2ca | 501 | // Saved replies (per-user canned comment templates) |
| 502 | app.route("/", savedReplyRoutes); | |
| 503 | ||
| 504 | // Environments + deployment history UI | |
| 505 | app.route("/", deploymentRoutes); | |
| 2c61840 | 506 | // Unified CI/CD pipeline timeline |
| 507 | app.route("/", pipelineRoutes); | |
| 24cf2ca | 508 | |
| 6563f0a | 509 | // Organizations + teams (Block B1) |
| 510 | app.route("/", orgRoutes); | |
| 511 | ||
| c81ab7a | 512 | // API tokens |
| 513 | app.route("/", tokenRoutes); | |
| 514 | ||
| 59b6fb2 | 515 | // Notifications |
| 3ef4c9d | 516 | app.route("/", notificationRoutes); |
| 517 | ||
| 79136bb | 518 | // Repo settings (description, visibility, delete) |
| 519 | app.route("/", repoSettings); | |
| 479dcd9 | 520 | // Per-repo automation settings (off / suggest / auto) — migration 0106 |
| 521 | app.route("/", automationSettingsRoutes); | |
| 79136bb | 522 | |
| 23d1a81 | 523 | // Repo collaborators (add/list/remove) |
| 524 | app.route("/", collaboratorRoutes); | |
| 525 | ||
| 04f6b7f | 526 | // Team-based repo collaborators (invite a whole team) |
| 527 | app.route("/", teamCollaboratorRoutes); | |
| 528 | ||
| 529 | // Collaborator invite accept flow (token-based) | |
| 530 | app.route("/", invitesRoutes); | |
| 531 | ||
| 532 | // Real-time SSE endpoint (topic-based live updates) | |
| 533 | app.route("/", liveEventsRoutes); | |
| 534 | ||
| 3c03977 | 535 | // PR live co-editing — presence + cursors + content sync via SSE. |
| 536 | app.route("/", prLiveRoutes); | |
| 537 | ||
| c81ab7a | 538 | // Webhooks management |
| 539 | app.route("/", webhookRoutes); | |
| 540 | ||
| 79136bb | 541 | // Compare view (branch diffs) |
| 542 | app.route("/", compareRoutes); | |
| 543 | ||
| 544 | // Issue tracker | |
| 545 | app.route("/", issueRoutes); | |
| 546 | ||
| 85c4e13 | 547 | // Milestones — group issues + PRs toward a shared goal with due dates + progress tracking. |
| 548 | // Mounted after issueRoutes so /:owner/:repo/issues/* paths win before the milestone patterns. | |
| 549 | app.route("/", milestonesRoutes); | |
| 550 | ||
| f928118 | 551 | // Ship Agent — autonomous AI feature implementation |
| 552 | app.route("/", shipAgentRoutes); | |
| 553 | ||
| 77cf834 | 554 | // AI Copilot Workspace — issue-to-PR autonomous agent |
| 555 | app.route("/", workspaceRoutes); | |
| 2c61840 | 556 | app.route("/", workspaceHubRoutes); |
| 77cf834 | 557 | |
| cb5a796 | 558 | // Comment moderation queue — owner-only `/:owner/:repo/comments/pending` |
| 559 | // + per-row approve/reject/spam actions. Mounted before `pullRoutes` so | |
| 560 | // the `/:owner/:repo/comments/*` paths resolve before the broader PR | |
| 561 | // patterns kick in. | |
| 562 | app.route("/", commentModerationRoutes); | |
| 563 | ||
| 0074234 | 564 | // Pull requests |
| 565 | app.route("/", pullRoutes); | |
| 09d5f39 | 566 | |
| 2be65d0 | 567 | // Streaming PR review — SSE stream + embeddable widget |
| 568 | // Mounted immediately after pullRoutes so /:owner/:repo/pulls/:number/review/* | |
| 569 | // resolves before the webRoutes catch-all takes over. | |
| 570 | import streamingReviewRoutes from "./routes/streaming-review"; | |
| 571 | app.route("/", streamingReviewRoutes); | |
| 572 | ||
| 09d5f39 | 573 | // /stage PR preview — serve built static files from .stage-previews/{jobId}/ |
| 574 | // Registered immediately after pullRoutes so the path `/preview/:id/*` is | |
| 575 | // specific enough to never clash with repo browse routes (`/:owner/:repo/*`). | |
| 576 | app.get("/preview/:stageJobId/*", async (c) => { | |
| 577 | const { stageJobId } = c.req.param(); | |
| 578 | // Validate job ID format (UUID) | |
| 579 | if (!/^[0-9a-f-]{32,}$/i.test(stageJobId)) { | |
| 580 | return c.text("Not found", 404); | |
| 581 | } | |
| 582 | const { getPreviewDir, isPreviewExpired } = await import("./lib/pr-stage"); | |
| 583 | if (isPreviewExpired(stageJobId)) { | |
| 584 | return c.html( | |
| 585 | "<html><body style='font-family:sans-serif;padding:40px;color:#888'>" + | |
| 586 | "<h2>Preview expired</h2><p>This stage preview has expired (48h TTL). " + | |
| 587 | "Comment <code>/stage</code> on the PR to redeploy.</p></body></html>", | |
| 588 | 410 | |
| 589 | ); | |
| 590 | } | |
| 591 | const { join } = await import("path"); | |
| 592 | const previewDir = getPreviewDir(stageJobId); | |
| 593 | // Extract the wildcard path after /preview/:id/ | |
| 594 | const rawPath = c.req.path.replace(/^\/preview\/[^/]+/, "") || "/"; | |
| 595 | const filePath = rawPath === "/" || rawPath === "" ? "/index.html" : rawPath; | |
| 596 | const fullPath = join(previewDir, filePath); | |
| 597 | const file = Bun.file(fullPath); | |
| 598 | if (!(await file.exists())) { | |
| 599 | // Try index.html fallback (SPA behaviour) | |
| 600 | const indexFile = Bun.file(join(previewDir, "index.html")); | |
| 601 | if (await indexFile.exists()) { | |
| 602 | const html = await indexFile.text(); | |
| 603 | return c.html(html); | |
| 604 | } | |
| 605 | return c.text("Not found", 404); | |
| 606 | } | |
| 607 | const content = await file.arrayBuffer(); | |
| 608 | const ext = fullPath.split(".").pop()?.toLowerCase() ?? ""; | |
| 609 | const contentTypeMap: Record<string, string> = { | |
| 610 | html: "text/html; charset=utf-8", | |
| 611 | htm: "text/html; charset=utf-8", | |
| 612 | css: "text/css; charset=utf-8", | |
| 613 | js: "application/javascript; charset=utf-8", | |
| 614 | mjs: "application/javascript; charset=utf-8", | |
| 615 | json: "application/json; charset=utf-8", | |
| 616 | png: "image/png", | |
| 617 | jpg: "image/jpeg", | |
| 618 | jpeg: "image/jpeg", | |
| 619 | gif: "image/gif", | |
| 620 | svg: "image/svg+xml", | |
| 621 | ico: "image/x-icon", | |
| 622 | webp: "image/webp", | |
| 623 | woff: "font/woff", | |
| 624 | woff2: "font/woff2", | |
| 625 | ttf: "font/ttf", | |
| 626 | txt: "text/plain; charset=utf-8", | |
| 627 | xml: "application/xml", | |
| 628 | webmanifest: "application/manifest+json", | |
| 629 | }; | |
| 630 | const ct = contentTypeMap[ext] ?? "application/octet-stream"; | |
| 631 | return c.body(content, 200, { | |
| 632 | "content-type": ct, | |
| 633 | "cache-control": "public, max-age=300", | |
| 634 | "x-stage-job-id": stageJobId, | |
| 635 | }); | |
| 636 | }); | |
| 637 | ||
| 79ed944 | 638 | // PR sandboxes — runnable per-PR environments. Migration 0067. |
| 639 | app.route("/", prSandboxRoutes); | |
| 0074234 | 640 | |
| 9b3a183 | 641 | // Cloud dev environments — hosted VS Code in the browser. Migration 0072. |
| 642 | app.route("/", devEnvRoutes); | |
| 643 | ||
| c81ab7a | 644 | // Fork |
| 645 | app.route("/", forkRoutes); | |
| 646 | ||
| 0074234 | 647 | // Web file editor |
| 648 | app.route("/", editorRoutes); | |
| 649 | ||
| 6f2809f | 650 | // AI editor API routes (inline suggestions, explain, fix) |
| 651 | app.route("/", aiEditorRoutes); | |
| 652 | ||
| 43de941 | 653 | // Contributors |
| 654 | app.route("/", contributorRoutes); | |
| 655 | ||
| 699e5c7 | 656 | // Health liveness + metrics endpoints |
| 2c34075 | 657 | app.route("/", healthRoutes); |
| 658 | ||
| f295f78 | 659 | // Cross-product platform status (public, CORS-open — see docs/PLATFORM_STATUS.md) |
| 660 | app.route("/api/platform-status", platformStatus); | |
| 661 | ||
| 52ad8b1 | 662 | // Block L4 — Public stats counters (powers landing-page social proof) |
| 663 | app.route("/", publicStatsRoutes); | |
| 664 | ||
| 665 | // Block L3 — Live /demo page + /api/v2/demo/* endpoints | |
| 666 | app.route("/", demoRoutes); | |
| 667 | ||
| 2316be6 | 668 | // Public /status — human-readable platform health page |
| 669 | app.route("/", statusRoutes); | |
| 670 | ||
| b1be050 | 671 | // BLOCK S4 — Site-admin synthetic-monitor dashboard (/admin/status). |
| 672 | // Mounted near the public status route so the two surfaces are visible | |
| 673 | // side-by-side; routes are gated by isSiteAdmin internally. | |
| 674 | app.route("/", adminStatusRoutes); | |
| 675 | ||
| 80bed05 | 676 | // /help — quickstart + API cheatsheet |
| 677 | app.route("/", helpRoutes); | |
| 678 | ||
| e0e4219 | 679 | // /docs — expanded documentation site (getting started, workflow YAML, MCP, API, agents) |
| 680 | app.route("/", docsRoutes); | |
| 681 | ||
| 5f2e749 | 682 | // L8 — public /pricing page (free-tier polish). Mounted BEFORE marketing |
| 683 | // so the new editorial pricing layout wins the route; the legacy marketing | |
| 684 | // pricing remains as a safety net but is shadowed at the router. | |
| 685 | app.route("/", pricingRoutes); | |
| 686 | ||
| e1fc7db | 687 | // /changelog — manually curated platform release history |
| 688 | app.route("/", changelogRoutes); | |
| 689 | ||
| 9f29b65 | 690 | // Enterprise sales page + contact form lead capture. |
| 691 | app.route("/", enterpriseRoutes); | |
| 692 | ||
| b0148e9 | 693 | // /pricing, /features, /about — marketing surface |
| 694 | app.route("/", marketingRoutes); | |
| 695 | ||
| adf5e18 | 696 | // /developer-program — partner + marketplace revenue-share page |
| 697 | app.route("/", developerProgramRoutes); | |
| 698 | ||
| 5618f9a | 699 | // SEO: robots.txt + sitemap.xml |
| 700 | app.route("/", seoRoutes); | |
| 701 | ||
| 05cdb85 | 702 | // /api/version — live build SHA + uptime; client poller uses this to |
| 703 | // surface 'New version available — reload' banners on deploy. | |
| 704 | app.route("/", versionRoutes); | |
| 705 | ||
| 699e5c7 | 706 | // Health dashboard (per-repo health page) |
| 707 | app.route("/", healthDashboardRoutes); | |
| 708 | ||
| 9dd96b9 | 709 | // Block R1 — site-admin operations console. MUST be mounted BEFORE |
| 710 | // insightRoutes because its POST `/:owner/:repo/rollback` catch-all would | |
| 711 | // otherwise intercept `/admin/ops/rollback` (matching :owner=admin :repo=ops). | |
| 712 | app.route("/", adminOpsRoutes); | |
| f2c00b4 | 713 | // BLOCK W — Self-host status + bootstrap dashboard. |
| 714 | app.route("/", adminSelfHostRoutes); | |
| 826eccf | 715 | // BLOCK X — AI health-scan diagnose page (/admin/diagnose). |
| 716 | app.route("/", adminDiagnoseRoutes); | |
| f9814d2 | 717 | // Unified admin command center — /admin/command |
| 718 | app.route("/", adminCommandRoutes); | |
| 9dd96b9 | 719 | |
| 16b325c | 720 | // Insights (time-travel, dependencies, rollback) |
| 721 | app.route("/", insightRoutes); | |
| 722 | ||
| 8286942 | 723 | // Engineering Intelligence Dashboard — /insights + /:owner/:repo/insights/engineering |
| 724 | app.route("/", engineeringInsightsRoutes); | |
| 725 | ||
| 8d1483c | 726 | // DORA metrics page (/:owner/:repo/insights/dora) |
| 727 | app.route("/", doraRoutes); | |
| 728 | ||
| f1ab587 | 729 | // Command center dashboard |
| 730 | app.route("/", dashboardRoutes); | |
| 731 | ||
| 36b4cbd | 732 | // Legal pages (terms, privacy, AUP) |
| 733 | app.route("/", legalRoutes); | |
| 4b66018 | 734 | // Long-form legal sub-pages — /legal/{terms,privacy,acceptable-use,dmca}. |
| 735 | // The main `legal.tsx` serves the short canonical paths (/terms, /privacy, | |
| 736 | // /acceptable-use); these are the formal versions that the legal pages | |
| 737 | // internally link to each other. | |
| 738 | app.route("/", legalTermsRoutes); | |
| 739 | app.route("/", legalPrivacyRoutes); | |
| 740 | app.route("/", legalAcceptableUseRoutes); | |
| 741 | app.route("/", legalDmcaRoutes); | |
| 36b4cbd | 742 | |
| bdbd0de | 743 | // GitHub import / migration |
| 744 | app.route("/", importRoutes); | |
| 14c3cc8 | 745 | app.route("/", importBulkRoutes); |
| f390cfa | 746 | app.route("/", importSecretsRoutes); |
| bb2dea9 | 747 | // GitHub Actions → Gluecron gates.yml importer (stateless converter) |
| 748 | app.route("/", actionsImporterRoutes); | |
| 14c3cc8 | 749 | app.route("/", migrationRoutes); |
| ba23fe2 | 750 | app.route("/", migrationAssistantRoutes); |
| 9a8b8de | 751 | // GitHub Org Migration Wizard — live progress bulk importer |
| 752 | app.route("/", migrateRoutes); | |
| 14c3cc8 | 753 | |
| 754 | // Spec-to-PR (experimental AI-generated draft PRs) | |
| 755 | app.route("/", specsRoutes); | |
| 23d0abf | 756 | app.route("/", refactorRoutes); |
| b665cac | 757 | app.route("/", codebaseMigratorRoutes); |
| bdbd0de | 758 | |
| c81ab7a | 759 | // Explore page |
| 760 | app.route("/", exploreRoutes); | |
| 761 | ||
| 59b6fb2 | 762 | // Onboarding |
| 763 | app.route("/", onboardingRoutes); | |
| 764 | ||
| 0316dbb | 765 | // Admin + feature routes |
| 766 | app.route("/", adminRoutes); | |
| 7293c67 | 767 | app.route("/", adminDeletionsRoutes); |
| 768 | app.route("/", adminStripeRoutes); | |
| ba9e143 | 769 | |
| 770 | // SOC 2 security dashboard + readiness checklist (/admin/security, /admin/soc2) | |
| 771 | app.route("/", adminSecurityRoutes); | |
| 509c376 | 772 | app.route("/", adminIntegrationsRoutes); |
| bc519ae | 773 | app.route("/", adminEnvHealthRoutes); |
| 79ed944 | 774 | app.route("/", adminAdvancementRoutes); |
| f764c07 | 775 | app.route("/", adminDeploysRoutes); |
| 776 | app.route("/", adminDeploysPageRoutes); | |
| 783dd46 | 777 | app.route("/", adminServerTargetsRoutes); |
| 9aaa128 | 778 | app.route("/", deployTargetsRoutes); |
| 90c7531 | 779 | app.route("/", claudeWebRoutes); |
| 9dd96b9 | 780 | // Note: adminOpsRoutes is mounted earlier (before insightRoutes) — see comment above. |
| 0316dbb | 781 | app.route("/", advisoriesRoutes); |
| 782 | app.route("/", aiChangelogRoutes); | |
| 0a69faa | 783 | // "Explain This Repo" — rich structured AI analysis dashboard (mounted before |
| 784 | // the simpler aiExplainRoutes so the new routes win on /:owner/:repo/explain). | |
| 785 | app.route("/", explainRoutes); | |
| 0316dbb | 786 | app.route("/", aiExplainRoutes); |
| 2be65d0 | 787 | app.route("/", archaeologyRoutes); |
| 0316dbb | 788 | app.route("/", aiTestsRoutes); |
| 789 | app.route("/", askRoutes); | |
| 38d31d3 | 790 | app.route("/", repoChatRoutes); |
| ee7e577 | 791 | // Personal cross-repo chat — `/chat` (user-scoped). Mounted alongside |
| 792 | // repoChatRoutes so the two surfaces share the catch-all priority. | |
| 793 | app.route("/", personalChatRoutes); | |
| 0316dbb | 794 | app.route("/", billingRoutes); |
| 8809b87 | 795 | app.route("/", billingUsageRoutes); |
| 6778ad2 | 796 | app.route("/", stripeWebhookRoutes); |
| 0316dbb | 797 | app.route("/", codeScanningRoutes); |
| da3fc18 | 798 | // Dependency CVE scanner findings page — /:owner/:repo/security/vulnerabilities |
| 799 | app.route("/", securityRoutes); | |
| 0316dbb | 800 | app.route("/", commitStatusesRoutes); |
| 801 | app.route("/", copilotRoutes); | |
| f5d020f | 802 | app.route("/", pairProgrammerRoutes); |
| 0316dbb | 803 | app.route("/", depUpdaterRoutes); |
| 804 | app.route("/", depsRoutes); | |
| 805 | app.route("/", discussionsRoutes); | |
| 806 | app.route("/", environmentsRoutes); | |
| 4bbacbe | 807 | app.route("/", previewsRoutes); |
| 79ed944 | 808 | app.route("/", docsTrackingRoutes); |
| 0316dbb | 809 | app.route("/", followsRoutes); |
| 810 | app.route("/", gatesRoutes); | |
| 811 | app.route("/", gistsRoutes); | |
| 812 | app.route("/", graphqlRoutes); | |
| 2c2163e | 813 | app.route("/", mcpRoutes); |
| 0316dbb | 814 | app.route("/", marketplaceRoutes); |
| 5ca514a | 815 | app.route("/", marketplaceAgentsRoutes); |
| 0316dbb | 816 | app.route("/", mergeQueueRoutes); |
| 817 | app.route("/", mirrorsRoutes); | |
| 818 | app.route("/", orgInsightsRoutes); | |
| b02ce30 | 819 | app.route("/", orgHealthRoutes); |
| 0316dbb | 820 | app.route("/", packagesRoutes); |
| 821 | app.route("/", packagesApiRoutes); | |
| 845fd8a | 822 | // OCI / Docker container registry — /v2/* (OCI Distribution Spec v1.0) |
| 823 | app.route("/", ociRegistryRoutes); | |
| 0316dbb | 824 | app.route("/", pagesRoutes); |
| 825 | app.route("/", projectsRoutes); | |
| 826 | app.route("/", protectedTagsRoutes); | |
| 827 | app.route("/", pwaRoutes); | |
| 46d6165 | 828 | app.route("/", installRoutes); |
| cd4f63b | 829 | // BLOCK Q1 — /gluecron.dxt download (Claude Desktop one-click extension) |
| 830 | app.route("/", dxtRoutes); | |
| 662ce86 | 831 | // Connect Claude — user-facing one-click MCP setup (/connect/claude). Mounted |
| 832 | // next to the other one-click flows (install.sh + .dxt) for surface symmetry. | |
| 833 | app.route("/", connectClaudeRoutes); | |
| f5b9ef5 | 834 | // Claude Code Integration Receiver — /api/claude/connect + /api/claude/session. |
| 835 | app.route("/", claudeIntegration); | |
| 836 | // Connect guide — public onboarding page (/connect/claude-guide). | |
| 837 | app.route("/", connectRoutes); | |
| 05ab9b1 | 838 | // Push Watch — per-commit live status (gates + deploy + latency) at /:owner/:repo/push/:sha |
| 839 | app.route("/", pushWatchRoutes); | |
| 840 | // Org Secrets Manager — BLOCK M2 — /orgs/:slug/settings/secrets | |
| 841 | app.route("/", orgSecretsRoutes); | |
| a2b3e99 | 842 | // Cross-repo code search — BLOCK M3 — /search/code + /api/search/code |
| 843 | app.route("/", crossRepoSearchRoutes); | |
| 844 | // Browser push notifications — BLOCK M4 — /settings/notifications/push + /api/push/* | |
| 845 | app.route("/", pushNotifRoutes); | |
| 9fbe6cd | 846 | // Developer Velocity Dashboard — BLOCK M9 — /:owner/:repo/insights/velocity |
| 847 | app.route("/", velocityRoutes); | |
| 848 | // Stale Branch Cleanup — BLOCK M10 — /:owner/:repo/branches/stale | |
| 849 | app.route("/", staleBranchRoutes); | |
| 22f43f3 | 850 | // Repository Pulse — BLOCK M12 — /:owner/:repo/pulse |
| 851 | app.route("/", pulseRoutes); | |
| 74d8c4d | 852 | // Repository Health Score — BLOCK M14 — /:owner/:repo/insights/health |
| 853 | app.route("/", healthScoreRoutes); | |
| 77cf834 | 854 | // Repository Health Score breakdown page — /:owner/:repo/health |
| 855 | app.route("/", repoHealthRoutes); | |
| 74d8c4d | 856 | // Hot Files Heatmap — BLOCK M16 — /:owner/:repo/insights/hotfiles |
| 857 | app.route("/", hotFilesRoutes); | |
| bcc4020 | 858 | // AI Technical Debt Map — /:owner/:repo/debt-map (visual debt graph + Claude analysis) |
| 859 | app.route("/", debtMapRoutes); | |
| 1d6db4d | 860 | // Bus Factor Analysis — /:owner/:repo/insights/bus-factor |
| 861 | app.route("/", busFactorRoutes); | |
| b02ce30 | 862 | // Test Gap Detector — /:owner/:repo/insights/test-gaps |
| 863 | app.route("/", testGapsRoutes); | |
| f5d020f | 864 | // Cross-Repo Dependency Impact Detection — /:owner/:repo/pulls/:number/cross-repo-impact |
| 865 | app.route("/", crossRepoImpactRoutes); | |
| ebbb527 | 866 | // Hosted Claude tool-use loops — paste loop, get endpoint, billing meter. |
| 867 | // See src/routes/claude-deploy.tsx + src/lib/hosted-claude-loop.ts. | |
| 868 | app.route("/", claudeDeployRoutes); | |
| 0316dbb | 869 | app.route("/", releasesRoutes); |
| 870 | app.route("/", requiredChecksRoutes); | |
| 871 | app.route("/", rulesetsRoutes); | |
| 872 | app.route("/", searchRoutes); | |
| 873 | app.route("/", semanticSearchRoutes); | |
| 77cf834 | 874 | app.route("/", nlSearchRoutes); |
| 0316dbb | 875 | app.route("/", signingKeysRoutes); |
| 876 | app.route("/", sponsorsRoutes); | |
| 877 | app.route("/", ssoRoutes); | |
| 3a845e4 | 878 | // Enterprise per-org SAML 2.0 + OIDC SSO routes |
| 879 | app.route("/", samlSsoRoutes); | |
| 880 | // SCIM 2.0 user provisioning endpoints | |
| 881 | app.route("/", scimRoutes); | |
| 882 | // Per-org SSO + SCIM admin settings UI | |
| 883 | app.route("/", orgSsoSettingsRoutes); | |
| 46d6165 | 884 | app.route("/", githubOauthRoutes); |
| 582cdac | 885 | app.route("/", googleOauthRoutes); |
| 0316dbb | 886 | app.route("/", symbolsRoutes); |
| 887 | app.route("/", templatesRoutes); | |
| 888 | app.route("/", trafficRoutes); | |
| 889 | app.route("/", wikisRoutes); | |
| 890 | app.route("/", workflowsRoutes); | |
| 5ff9cc2 | 891 | app.route("/", workflowArtifactsRoutes); |
| 892 | app.route("/", workflowSecretsRoutes); | |
| 46d6165 | 893 | app.route("/", sleepModeRoutes); |
| 52ad8b1 | 894 | app.route("/", vsGithubRoutes); |
| 0316dbb | 895 | |
| 45f3b73 | 896 | // Voice-to-PR — phone-first dictation → spec or issue |
| 897 | app.route("/", voiceRoutes); | |
| 898 | ||
| 3122762 | 899 | // Blog / Devlog — public posts, no DB |
| 900 | app.route("/", blogRoutes); | |
| 901 | ||
| cd4f63b | 902 | // Block Q3 — Anonymous playground (`/play`, `/play/claim`). Mounted |
| 903 | // before the web catch-all so the bare `/play` literal wins over the | |
| 904 | // `/:owner` user-profile route. | |
| 905 | app.route("/", playgroundRoutes); | |
| 906 | ||
| 891efbe | 907 | // Shareable AI hours-saved OG image card + landing page. |
| 908 | // /share/hours-saved?user=:username → 1200×630 SVG (og:image) | |
| 909 | // /share/:username → HTML page with og:image meta + Twitter share | |
| 910 | // Mounted BEFORE webRoutes so /share/* doesn't fall through to the /:owner profile route. | |
| 911 | app.route("/", shareRoutes); | |
| 912 | ||
| 79136bb | 913 | // Web UI (catch-all, must be last) |
| 914 | app.route("/", webRoutes); | |
| 915 | ||
| c63b860 | 916 | // Global 404 — BLOCK O2 routes the shared `NotFoundPage` view so |
| 917 | // the markup stays consistent with /500 and the admin /403 page. | |
| 79136bb | 918 | app.notFound((c) => { |
| 36cc17a | 919 | const user = c.get("user") ?? null; |
| 79136bb | 920 | return c.html( |
| c63b860 | 921 | <NotFoundPage user={user} method={c.req.method} path={c.req.path} />, |
| 79136bb | 922 | 404 |
| 923 | ); | |
| 924 | }); | |
| 925 | ||
| c63b860 | 926 | // Global error handler — BLOCK O2 uses the shared `ServerErrorPage` |
| 927 | // view. Trace block only shown outside production. | |
| 79136bb | 928 | app.onError((err, c) => { |
| 80bed05 | 929 | reportError(err, { |
| 930 | requestId: c.get("requestId"), | |
| 931 | path: c.req.path, | |
| 932 | method: c.req.method, | |
| 933 | }); | |
| c63b860 | 934 | // Prefer the inbound `x-request-id` header (LB-supplied) and fall |
| 935 | // back to the context value set by request-context middleware. | |
| 936 | const requestId = | |
| 937 | c.req.header("x-request-id") || | |
| 938 | ((c.get("requestId" as never) as string | undefined) ?? undefined); | |
| 36cc17a | 939 | const user = c.get("user") ?? null; |
| c63b860 | 940 | const trace = |
| 941 | process.env.NODE_ENV !== "production" && err && err.message | |
| 942 | ? err.message | |
| 943 | : undefined; | |
| 79136bb | 944 | return c.html( |
| c63b860 | 945 | <ServerErrorPage user={user} requestId={requestId} trace={trace} />, |
| 79136bb | 946 | 500 |
| 947 | ); | |
| 948 | }); | |
| 949 | ||
| 950 | export default app; |