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