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"; |
| 3ef4c9d | 6 | import { requestContext } from "./middleware/request-context"; |
| 7 | import { rateLimit } from "./middleware/rate-limit"; | |
| 79136bb | 8 | import gitRoutes from "./routes/git"; |
| 9 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 10 | import apiV2Routes from "./routes/api-v2"; |
| 11 | import apiDocsRoutes from "./routes/api-docs"; | |
| 79136bb | 12 | import authRoutes from "./routes/auth"; |
| 13 | import settingsRoutes from "./routes/settings"; | |
| 7298a17 | 14 | import settings2faRoutes from "./routes/settings-2fa"; |
| 79136bb | 15 | import issueRoutes from "./routes/issues"; |
| 16 | import repoSettings from "./routes/repo-settings"; | |
| 17 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 18 | import pullRoutes from "./routes/pulls"; |
| 19 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 20 | import forkRoutes from "./routes/fork"; |
| 21 | import webhookRoutes from "./routes/webhooks"; | |
| 22 | import exploreRoutes from "./routes/explore"; | |
| 23 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 24 | import contributorRoutes from "./routes/contributors"; |
| 699e5c7 | 25 | import healthRoutes from "./routes/health-probe"; |
| 26 | import healthDashboardRoutes from "./routes/health"; | |
| 16b325c | 27 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 28 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 29 | import legalRoutes from "./routes/legal"; |
| 79136bb | 30 | import webRoutes from "./routes/web"; |
| 0316dbb | 31 | import hookRoutes from "./routes/hooks"; |
| 32 | import eventsRoutes from "./routes/events"; | |
| 33 | import passkeyRoutes from "./routes/passkeys"; | |
| 34 | import oauthRoutes from "./routes/oauth"; | |
| 35 | import developerAppsRoutes from "./routes/developer-apps"; | |
| 36 | import themeRoutes from "./routes/theme"; | |
| 37 | import auditRoutes from "./routes/audit"; | |
| 38 | import reactionRoutes from "./routes/reactions"; | |
| 39 | import savedReplyRoutes from "./routes/saved-replies"; | |
| 40 | import deploymentRoutes from "./routes/deployments"; | |
| 41 | import orgRoutes from "./routes/orgs"; | |
| 42 | import notificationRoutes from "./routes/notifications"; | |
| 43 | import onboardingRoutes from "./routes/onboarding"; | |
| 44 | import adminRoutes from "./routes/admin"; | |
| 45 | import advisoriesRoutes from "./routes/advisories"; | |
| 46 | import aiChangelogRoutes from "./routes/ai-changelog"; | |
| 47 | import aiExplainRoutes from "./routes/ai-explain"; | |
| 48 | import aiTestsRoutes from "./routes/ai-tests"; | |
| 49 | import askRoutes from "./routes/ask"; | |
| 50 | import billingRoutes from "./routes/billing"; | |
| 51 | import codeScanningRoutes from "./routes/code-scanning"; | |
| 52 | import commitStatusesRoutes from "./routes/commit-statuses"; | |
| 53 | import copilotRoutes from "./routes/copilot"; | |
| 54 | import depUpdaterRoutes from "./routes/dep-updater"; | |
| 55 | import depsRoutes from "./routes/deps"; | |
| 56 | import discussionsRoutes from "./routes/discussions"; | |
| 57 | import environmentsRoutes from "./routes/environments"; | |
| 58 | import followsRoutes from "./routes/follows"; | |
| 59 | import gatesRoutes from "./routes/gates"; | |
| 60 | import gistsRoutes from "./routes/gists"; | |
| 61 | import graphqlRoutes from "./routes/graphql"; | |
| 62 | import marketplaceRoutes from "./routes/marketplace"; | |
| 63 | import mergeQueueRoutes from "./routes/merge-queue"; | |
| 64 | import mirrorsRoutes from "./routes/mirrors"; | |
| 65 | import orgInsightsRoutes from "./routes/org-insights"; | |
| 66 | import packagesRoutes from "./routes/packages"; | |
| 67 | import packagesApiRoutes from "./routes/packages-api"; | |
| 68 | import pagesRoutes from "./routes/pages"; | |
| 69 | import projectsRoutes from "./routes/projects"; | |
| 70 | import protectedTagsRoutes from "./routes/protected-tags"; | |
| 71 | import pwaRoutes from "./routes/pwa"; | |
| 72 | import releasesRoutes from "./routes/releases"; | |
| 73 | import requiredChecksRoutes from "./routes/required-checks"; | |
| 74 | import rulesetsRoutes from "./routes/rulesets"; | |
| 75 | import searchRoutes from "./routes/search"; | |
| 76 | import semanticSearchRoutes from "./routes/semantic-search"; | |
| 77 | import signingKeysRoutes from "./routes/signing-keys"; | |
| 78 | import sponsorsRoutes from "./routes/sponsors"; | |
| 79 | import ssoRoutes from "./routes/sso"; | |
| 80 | import symbolsRoutes from "./routes/symbols"; | |
| 81 | import templatesRoutes from "./routes/templates"; | |
| 82 | import trafficRoutes from "./routes/traffic"; | |
| 83 | import wikisRoutes from "./routes/wikis"; | |
| 84 | import workflowsRoutes from "./routes/workflows"; | |
| 59b6fb2 | 85 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 86 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 87 | |
| 88 | const app = new Hono(); | |
| 89 | ||
| 3ef4c9d | 90 | // Request context (request ID, start time) runs before everything else |
| 91 | app.use("*", requestContext); | |
| 05b973e | 92 | // Middleware — compression first (wraps all responses) |
| 93 | app.use("*", compress()); | |
| 94 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 95 | app.use("*", async (c, next) => { | |
| 96 | if (c.req.path.includes(".git/")) return next(); | |
| 97 | return logger()(c, next); | |
| 98 | }); | |
| 79136bb | 99 | app.use("/api/*", cors()); |
| 3ef4c9d | 100 | // Rate-limit API + auth endpoints (generous default) |
| 0316dbb | 101 | app.use("/api/*", rateLimit(120, 60_000, "api")); |
| 102 | app.use("/login", rateLimit(20, 60_000, "login")); | |
| 103 | app.use("/register", rateLimit(10, 60_000, "register")); | |
| 79136bb | 104 | |
| 59b6fb2 | 105 | // CSRF protection — set token on all requests, validate on mutations |
| 106 | app.use("*", csrfToken); | |
| 107 | app.use("*", csrfProtect); | |
| 108 | ||
| 45e31d0 | 109 | // Rate limit auth routes |
| 110 | app.use("/login", authRateLimit); | |
| 111 | app.use("/register", authRateLimit); | |
| 112 | ||
| 59b6fb2 | 113 | // Rate limit git operations |
| 114 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 115 | ||
| 116 | // Rate limit search | |
| 117 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 118 | app.use("/explore", searchRateLimit); | |
| 79136bb | 119 | |
| 120 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 121 | app.route("/", gitRoutes); | |
| 122 | ||
| 45e31d0 | 123 | // REST API v1 (legacy) |
| 79136bb | 124 | app.route("/", apiRoutes); |
| 125 | ||
| 0316dbb | 126 | // REST API v2 (basePath /api/v2) |
| 127 | app.route("/", apiV2Routes); | |
| 128 | ||
| ad6d4ad | 129 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 130 | app.route("/", hookRoutes); | |
| 21f8dbd | 131 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 132 | |
| 45e31d0 | 133 | // API documentation |
| 134 | app.route("/", apiDocsRoutes); | |
| 79136bb | 135 | |
| 136 | // Auth routes (register, login, logout) | |
| 137 | app.route("/", authRoutes); | |
| 138 | ||
| 139 | // Settings routes (profile, SSH keys) | |
| 140 | app.route("/", settingsRoutes); | |
| 141 | ||
| 7298a17 | 142 | // 2FA / TOTP settings (Block B4) |
| 143 | app.route("/", settings2faRoutes); | |
| 144 | ||
| 2df1f8c | 145 | // WebAuthn / passkey routes (Block B5) |
| 146 | app.route("/", passkeyRoutes); | |
| 147 | ||
| 058d752 | 148 | // OAuth 2.0 provider (Block B6) |
| 149 | app.route("/", oauthRoutes); | |
| 150 | app.route("/", developerAppsRoutes); | |
| 151 | ||
| 6fc53bd | 152 | // Theme toggle (dark/light cookie) |
| 153 | app.route("/", themeRoutes); | |
| 154 | ||
| 155 | // Audit log UI | |
| 156 | app.route("/", auditRoutes); | |
| 157 | ||
| 158 | // Reactions API (issues, PRs, comments) | |
| 159 | app.route("/", reactionRoutes); | |
| 160 | ||
| 24cf2ca | 161 | // Saved replies (per-user canned comment templates) |
| 162 | app.route("/", savedReplyRoutes); | |
| 163 | ||
| 164 | // Environments + deployment history UI | |
| 165 | app.route("/", deploymentRoutes); | |
| 166 | ||
| 6563f0a | 167 | // Organizations + teams (Block B1) |
| 168 | app.route("/", orgRoutes); | |
| 169 | ||
| c81ab7a | 170 | // API tokens |
| 171 | app.route("/", tokenRoutes); | |
| 172 | ||
| 59b6fb2 | 173 | // Notifications |
| 3ef4c9d | 174 | app.route("/", notificationRoutes); |
| 175 | ||
| 59b6fb2 | 176 | // Organizations |
| 177 | app.route("/", orgRoutes); | |
| 3ef4c9d | 178 | |
| 79136bb | 179 | // Repo settings (description, visibility, delete) |
| 180 | app.route("/", repoSettings); | |
| 181 | ||
| c81ab7a | 182 | // Webhooks management |
| 183 | app.route("/", webhookRoutes); | |
| 184 | ||
| 79136bb | 185 | // Compare view (branch diffs) |
| 186 | app.route("/", compareRoutes); | |
| 187 | ||
| 188 | // Issue tracker | |
| 189 | app.route("/", issueRoutes); | |
| 190 | ||
| 0074234 | 191 | // Pull requests |
| 192 | app.route("/", pullRoutes); | |
| 193 | ||
| c81ab7a | 194 | // Fork |
| 195 | app.route("/", forkRoutes); | |
| 196 | ||
| 0074234 | 197 | // Web file editor |
| 198 | app.route("/", editorRoutes); | |
| 199 | ||
| 43de941 | 200 | // Contributors |
| 201 | app.route("/", contributorRoutes); | |
| 202 | ||
| 699e5c7 | 203 | // Health liveness + metrics endpoints |
| 2c34075 | 204 | app.route("/", healthRoutes); |
| 205 | ||
| 699e5c7 | 206 | // Health dashboard (per-repo health page) |
| 207 | app.route("/", healthDashboardRoutes); | |
| 208 | ||
| 16b325c | 209 | // Insights (time-travel, dependencies, rollback) |
| 210 | app.route("/", insightRoutes); | |
| 211 | ||
| f1ab587 | 212 | // Command center dashboard |
| 213 | app.route("/", dashboardRoutes); | |
| 214 | ||
| 36b4cbd | 215 | // Legal pages (terms, privacy, AUP) |
| 216 | app.route("/", legalRoutes); | |
| 217 | ||
| c81ab7a | 218 | // Explore page |
| 219 | app.route("/", exploreRoutes); | |
| 220 | ||
| 59b6fb2 | 221 | // Onboarding |
| 222 | app.route("/", onboardingRoutes); | |
| 223 | ||
| 0316dbb | 224 | // Admin + feature routes |
| 225 | app.route("/", adminRoutes); | |
| 226 | app.route("/", advisoriesRoutes); | |
| 227 | app.route("/", aiChangelogRoutes); | |
| 228 | app.route("/", aiExplainRoutes); | |
| 229 | app.route("/", aiTestsRoutes); | |
| 230 | app.route("/", askRoutes); | |
| 231 | app.route("/", billingRoutes); | |
| 232 | app.route("/", codeScanningRoutes); | |
| 233 | app.route("/", commitStatusesRoutes); | |
| 234 | app.route("/", copilotRoutes); | |
| 235 | app.route("/", depUpdaterRoutes); | |
| 236 | app.route("/", depsRoutes); | |
| 237 | app.route("/", discussionsRoutes); | |
| 238 | app.route("/", environmentsRoutes); | |
| 239 | app.route("/", followsRoutes); | |
| 240 | app.route("/", gatesRoutes); | |
| 241 | app.route("/", gistsRoutes); | |
| 242 | app.route("/", graphqlRoutes); | |
| 243 | app.route("/", marketplaceRoutes); | |
| 244 | app.route("/", mergeQueueRoutes); | |
| 245 | app.route("/", mirrorsRoutes); | |
| 246 | app.route("/", orgInsightsRoutes); | |
| 247 | app.route("/", packagesRoutes); | |
| 248 | app.route("/", packagesApiRoutes); | |
| 249 | app.route("/", pagesRoutes); | |
| 250 | app.route("/", projectsRoutes); | |
| 251 | app.route("/", protectedTagsRoutes); | |
| 252 | app.route("/", pwaRoutes); | |
| 253 | app.route("/", releasesRoutes); | |
| 254 | app.route("/", requiredChecksRoutes); | |
| 255 | app.route("/", rulesetsRoutes); | |
| 256 | app.route("/", searchRoutes); | |
| 257 | app.route("/", semanticSearchRoutes); | |
| 258 | app.route("/", signingKeysRoutes); | |
| 259 | app.route("/", sponsorsRoutes); | |
| 260 | app.route("/", ssoRoutes); | |
| 261 | app.route("/", symbolsRoutes); | |
| 262 | app.route("/", templatesRoutes); | |
| 263 | app.route("/", trafficRoutes); | |
| 264 | app.route("/", wikisRoutes); | |
| 265 | app.route("/", workflowsRoutes); | |
| 266 | ||
| 79136bb | 267 | // Web UI (catch-all, must be last) |
| 268 | app.route("/", webRoutes); | |
| 269 | ||
| 270 | // Global 404 | |
| 271 | app.notFound((c) => { | |
| 272 | return c.html( | |
| 273 | <Layout title="Not Found"> | |
| 274 | <div class="empty-state"> | |
| 275 | <h2>404</h2> | |
| 276 | <p>Page not found.</p> | |
| 277 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 278 | Go home | |
| 279 | </a> | |
| 280 | </div> | |
| 281 | </Layout>, | |
| 282 | 404 | |
| 283 | ); | |
| 284 | }); | |
| 285 | ||
| 286 | // Global error handler | |
| 287 | app.onError((err, c) => { | |
| 288 | console.error("[error]", err); | |
| 289 | return c.html( | |
| 290 | <Layout title="Error"> | |
| 291 | <div class="empty-state"> | |
| 292 | <h2>Something went wrong</h2> | |
| 293 | <p>An unexpected error occurred.</p> | |
| 294 | {process.env.NODE_ENV !== "production" && ( | |
| 295 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 296 | {err.message} | |
| 297 | </pre> | |
| 298 | )} | |
| 299 | </div> | |
| 300 | </Layout>, | |
| 301 | 500 | |
| 302 | ); | |
| 303 | }); | |
| 304 | ||
| 305 | export default app; |