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