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"; |
| 2c34075 | 25 | import healthRoutes from "./routes/health"; |
| 16b325c | 26 | import insightRoutes from "./routes/insights"; |
| f1ab587 | 27 | import dashboardRoutes from "./routes/dashboard"; |
| 36b4cbd | 28 | import legalRoutes from "./routes/legal"; |
| bdbd0de | 29 | import importRoutes from "./routes/import"; |
| 79136bb | 30 | import webRoutes from "./routes/web"; |
| 59b6fb2 | 31 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 32 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 33 | |
| 34 | const app = new Hono(); | |
| 35 | ||
| 3ef4c9d | 36 | // Request context (request ID, start time) runs before everything else |
| 37 | app.use("*", requestContext); | |
| 05b973e | 38 | // Middleware — compression first (wraps all responses) |
| 39 | app.use("*", compress()); | |
| 40 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 41 | app.use("*", async (c, next) => { | |
| 42 | if (c.req.path.includes(".git/")) return next(); | |
| 43 | return logger()(c, next); | |
| 44 | }); | |
| 79136bb | 45 | app.use("/api/*", cors()); |
| 3ef4c9d | 46 | // Rate-limit API + auth endpoints (generous default) |
| 47 | app.use("/api/*", rateLimit({ windowMs: 60_000, max: 120 })); | |
| 48 | app.use("/login", rateLimit({ windowMs: 60_000, max: 20 })); | |
| 49 | app.use("/register", rateLimit({ windowMs: 60_000, max: 10 })); | |
| 79136bb | 50 | |
| 59b6fb2 | 51 | // CSRF protection — set token on all requests, validate on mutations |
| 52 | app.use("*", csrfToken); | |
| 53 | app.use("*", csrfProtect); | |
| 54 | ||
| 45e31d0 | 55 | // Rate limit auth routes |
| 56 | app.use("/login", authRateLimit); | |
| 57 | app.use("/register", authRateLimit); | |
| 58 | ||
| 59b6fb2 | 59 | // Rate limit git operations |
| 60 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 61 | ||
| 62 | // Rate limit search | |
| 63 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 64 | app.use("/explore", searchRateLimit); | |
| 79136bb | 65 | |
| 66 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 67 | app.route("/", gitRoutes); | |
| 68 | ||
| 45e31d0 | 69 | // REST API v1 (legacy) |
| 79136bb | 70 | app.route("/", apiRoutes); |
| 71 | ||
| ad6d4ad | 72 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 73 | app.route("/", hookRoutes); | |
| 21f8dbd | 74 | app.route("/api/events", eventsRoutes); |
| ad6d4ad | 75 | |
| 45e31d0 | 76 | // API documentation |
| 77 | app.route("/", apiDocsRoutes); | |
| 79136bb | 78 | |
| 79 | // Auth routes (register, login, logout) | |
| 80 | app.route("/", authRoutes); | |
| 81 | ||
| 82 | // Settings routes (profile, SSH keys) | |
| 83 | app.route("/", settingsRoutes); | |
| 84 | ||
| 7298a17 | 85 | // 2FA / TOTP settings (Block B4) |
| 86 | app.route("/", settings2faRoutes); | |
| 87 | ||
| 2df1f8c | 88 | // WebAuthn / passkey routes (Block B5) |
| 89 | app.route("/", passkeyRoutes); | |
| 90 | ||
| 058d752 | 91 | // OAuth 2.0 provider (Block B6) |
| 92 | app.route("/", oauthRoutes); | |
| 93 | app.route("/", developerAppsRoutes); | |
| 94 | ||
| 6fc53bd | 95 | // Theme toggle (dark/light cookie) |
| 96 | app.route("/", themeRoutes); | |
| 97 | ||
| 98 | // Audit log UI | |
| 99 | app.route("/", auditRoutes); | |
| 100 | ||
| 101 | // Reactions API (issues, PRs, comments) | |
| 102 | app.route("/", reactionRoutes); | |
| 103 | ||
| 24cf2ca | 104 | // Saved replies (per-user canned comment templates) |
| 105 | app.route("/", savedReplyRoutes); | |
| 106 | ||
| 107 | // Environments + deployment history UI | |
| 108 | app.route("/", deploymentRoutes); | |
| 109 | ||
| 6563f0a | 110 | // Organizations + teams (Block B1) |
| 111 | app.route("/", orgRoutes); | |
| 112 | ||
| c81ab7a | 113 | // API tokens |
| 114 | app.route("/", tokenRoutes); | |
| 115 | ||
| 59b6fb2 | 116 | // Notifications |
| 3ef4c9d | 117 | app.route("/", notificationRoutes); |
| 118 | ||
| 59b6fb2 | 119 | // Organizations |
| 120 | app.route("/", orgRoutes); | |
| 3ef4c9d | 121 | |
| 79136bb | 122 | // Repo settings (description, visibility, delete) |
| 123 | app.route("/", repoSettings); | |
| 124 | ||
| c81ab7a | 125 | // Webhooks management |
| 126 | app.route("/", webhookRoutes); | |
| 127 | ||
| 79136bb | 128 | // Compare view (branch diffs) |
| 129 | app.route("/", compareRoutes); | |
| 130 | ||
| 131 | // Issue tracker | |
| 132 | app.route("/", issueRoutes); | |
| 133 | ||
| 0074234 | 134 | // Pull requests |
| 135 | app.route("/", pullRoutes); | |
| 136 | ||
| c81ab7a | 137 | // Fork |
| 138 | app.route("/", forkRoutes); | |
| 139 | ||
| 0074234 | 140 | // Web file editor |
| 141 | app.route("/", editorRoutes); | |
| 142 | ||
| 43de941 | 143 | // Contributors |
| 144 | app.route("/", contributorRoutes); | |
| 145 | ||
| 2c34075 | 146 | // Health dashboard |
| 147 | app.route("/", healthRoutes); | |
| 148 | ||
| 16b325c | 149 | // Insights (time-travel, dependencies, rollback) |
| 150 | app.route("/", insightRoutes); | |
| 151 | ||
| f1ab587 | 152 | // Command center dashboard |
| 153 | app.route("/", dashboardRoutes); | |
| 154 | ||
| 36b4cbd | 155 | // Legal pages (terms, privacy, AUP) |
| 156 | app.route("/", legalRoutes); | |
| 157 | ||
| bdbd0de | 158 | // GitHub import / migration |
| 159 | app.route("/", importRoutes); | |
| 160 | ||
| c81ab7a | 161 | // Explore page |
| 162 | app.route("/", exploreRoutes); | |
| 163 | ||
| 59b6fb2 | 164 | // Onboarding |
| 165 | app.route("/", onboardingRoutes); | |
| 166 | ||
| 79136bb | 167 | // Web UI (catch-all, must be last) |
| 168 | app.route("/", webRoutes); | |
| 169 | ||
| 170 | // Global 404 | |
| 171 | app.notFound((c) => { | |
| 172 | return c.html( | |
| 173 | <Layout title="Not Found"> | |
| 174 | <div class="empty-state"> | |
| 175 | <h2>404</h2> | |
| 176 | <p>Page not found.</p> | |
| 177 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 178 | Go home | |
| 179 | </a> | |
| 180 | </div> | |
| 181 | </Layout>, | |
| 182 | 404 | |
| 183 | ); | |
| 184 | }); | |
| 185 | ||
| 186 | // Global error handler | |
| 187 | app.onError((err, c) => { | |
| 188 | console.error("[error]", err); | |
| 189 | return c.html( | |
| 190 | <Layout title="Error"> | |
| 191 | <div class="empty-state"> | |
| 192 | <h2>Something went wrong</h2> | |
| 193 | <p>An unexpected error occurred.</p> | |
| 194 | {process.env.NODE_ENV !== "production" && ( | |
| 195 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 196 | {err.message} | |
| 197 | </pre> | |
| 198 | )} | |
| 199 | </div> | |
| 200 | </Layout>, | |
| 201 | 500 | |
| 202 | ); | |
| 203 | }); | |
| 204 | ||
| 205 | export default app; |