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"; | |
| 10 | import authRoutes from "./routes/auth"; | |
| 11 | import settingsRoutes from "./routes/settings"; | |
| 7298a17 | 12 | import settings2faRoutes from "./routes/settings-2fa"; |
| 79136bb | 13 | import issueRoutes from "./routes/issues"; |
| 14 | import repoSettings from "./routes/repo-settings"; | |
| 15 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 16 | import pullRoutes from "./routes/pulls"; |
| 17 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 18 | import forkRoutes from "./routes/fork"; |
| 19 | import webhookRoutes from "./routes/webhooks"; | |
| 20 | import exploreRoutes from "./routes/explore"; | |
| 21 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 22 | import contributorRoutes from "./routes/contributors"; |
| 3ef4c9d | 23 | import notificationRoutes from "./routes/notifications"; |
| 24 | import dashboardRoutes from "./routes/dashboard"; | |
| 25 | import askRoutes from "./routes/ask"; | |
| 26 | import releaseRoutes from "./routes/releases"; | |
| 27 | import gateRoutes from "./routes/gates"; | |
| 28 | import insightsRoutes from "./routes/insights"; | |
| 29 | import searchRoutes from "./routes/search"; | |
| 30 | import healthRoutes from "./routes/health"; | |
| ad6d4ad | 31 | import hookRoutes from "./routes/hooks"; |
| 6fc53bd | 32 | import themeRoutes from "./routes/theme"; |
| 33 | import auditRoutes from "./routes/audit"; | |
| 34 | import reactionRoutes from "./routes/reactions"; | |
| 24cf2ca | 35 | import savedReplyRoutes from "./routes/saved-replies"; |
| 36 | import deploymentRoutes from "./routes/deployments"; | |
| 6563f0a | 37 | import orgRoutes from "./routes/orgs"; |
| 2df1f8c | 38 | import passkeyRoutes from "./routes/passkeys"; |
| 058d752 | 39 | import oauthRoutes from "./routes/oauth"; |
| 40 | import developerAppsRoutes from "./routes/developer-apps"; | |
| eafe8c6 | 41 | import workflowRoutes from "./routes/workflows"; |
| 25a91a6 | 42 | import packagesApiRoutes from "./routes/packages-api"; |
| 43 | import packagesUiRoutes from "./routes/packages"; | |
| 44 | import pagesRoutes from "./routes/pages"; | |
| 45 | import environmentsRoutes from "./routes/environments"; | |
| 79136bb | 46 | import webRoutes from "./routes/web"; |
| 47 | ||
| 48 | const app = new Hono(); | |
| 49 | ||
| 3ef4c9d | 50 | // Request context (request ID, start time) runs before everything else |
| 51 | app.use("*", requestContext); | |
| 05b973e | 52 | // Middleware — compression first (wraps all responses) |
| 53 | app.use("*", compress()); | |
| 54 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 55 | app.use("*", async (c, next) => { | |
| 56 | if (c.req.path.includes(".git/")) return next(); | |
| 57 | return logger()(c, next); | |
| 58 | }); | |
| 79136bb | 59 | app.use("/api/*", cors()); |
| 3ef4c9d | 60 | // Rate-limit API + auth endpoints (generous default) |
| 61 | app.use("/api/*", rateLimit({ windowMs: 60_000, max: 120 })); | |
| 62 | app.use("/login", rateLimit({ windowMs: 60_000, max: 20 })); | |
| 63 | app.use("/register", rateLimit({ windowMs: 60_000, max: 10 })); | |
| 79136bb | 64 | |
| 65 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 66 | app.route("/", gitRoutes); | |
| 67 | ||
| 3ef4c9d | 68 | // Health + metrics |
| 69 | app.route("/", healthRoutes); | |
| 70 | ||
| ad6d4ad | 71 | // Inbound API hooks (GateTest callback + backup PAT-authed /api/v1/gate-runs) |
| 72 | app.route("/", hookRoutes); | |
| 73 | ||
| 79136bb | 74 | // REST API |
| 75 | app.route("/", apiRoutes); | |
| 76 | ||
| 77 | // Auth routes (register, login, logout) | |
| 78 | app.route("/", authRoutes); | |
| 79 | ||
| 80 | // Settings routes (profile, SSH keys) | |
| 81 | app.route("/", settingsRoutes); | |
| 82 | ||
| 7298a17 | 83 | // 2FA / TOTP settings (Block B4) |
| 84 | app.route("/", settings2faRoutes); | |
| 85 | ||
| 2df1f8c | 86 | // WebAuthn / passkey routes (Block B5) |
| 87 | app.route("/", passkeyRoutes); | |
| 88 | ||
| 058d752 | 89 | // OAuth 2.0 provider (Block B6) |
| 90 | app.route("/", oauthRoutes); | |
| 91 | app.route("/", developerAppsRoutes); | |
| 92 | ||
| 6fc53bd | 93 | // Theme toggle (dark/light cookie) |
| 94 | app.route("/", themeRoutes); | |
| 95 | ||
| 96 | // Audit log UI | |
| 97 | app.route("/", auditRoutes); | |
| 98 | ||
| 99 | // Reactions API (issues, PRs, comments) | |
| 100 | app.route("/", reactionRoutes); | |
| 101 | ||
| 24cf2ca | 102 | // Saved replies (per-user canned comment templates) |
| 103 | app.route("/", savedReplyRoutes); | |
| 104 | ||
| 105 | // Environments + deployment history UI | |
| 106 | app.route("/", deploymentRoutes); | |
| 107 | ||
| 6563f0a | 108 | // Organizations + teams (Block B1) |
| 109 | app.route("/", orgRoutes); | |
| 110 | ||
| c81ab7a | 111 | // API tokens |
| 112 | app.route("/", tokenRoutes); | |
| 113 | ||
| 3ef4c9d | 114 | // Notifications inbox |
| 115 | app.route("/", notificationRoutes); | |
| 116 | ||
| 117 | // Dashboard (/dashboard) | |
| 118 | app.route("/", dashboardRoutes); | |
| 119 | ||
| 120 | // AI assistant — /ask + /:owner/:repo/ask | |
| 121 | app.route("/", askRoutes); | |
| 122 | ||
| 123 | // Global search | |
| 124 | app.route("/", searchRoutes); | |
| 125 | ||
| 79136bb | 126 | // Repo settings (description, visibility, delete) |
| 127 | app.route("/", repoSettings); | |
| 128 | ||
| c81ab7a | 129 | // Webhooks management |
| 130 | app.route("/", webhookRoutes); | |
| 131 | ||
| 79136bb | 132 | // Compare view (branch diffs) |
| 133 | app.route("/", compareRoutes); | |
| 134 | ||
| 135 | // Issue tracker | |
| 136 | app.route("/", issueRoutes); | |
| 137 | ||
| 0074234 | 138 | // Pull requests |
| 139 | app.route("/", pullRoutes); | |
| 140 | ||
| c81ab7a | 141 | // Fork |
| 142 | app.route("/", forkRoutes); | |
| 143 | ||
| 0074234 | 144 | // Web file editor |
| 145 | app.route("/", editorRoutes); | |
| 146 | ||
| 43de941 | 147 | // Contributors |
| 148 | app.route("/", contributorRoutes); | |
| 149 | ||
| 3ef4c9d | 150 | // Releases |
| 151 | app.route("/", releaseRoutes); | |
| 152 | ||
| 153 | // Gates (history + settings + branch protection) | |
| 154 | app.route("/", gateRoutes); | |
| 155 | ||
| eafe8c6 | 156 | // Actions-equivalent workflow runner (Block C1) |
| 157 | app.route("/", workflowRoutes); | |
| 158 | ||
| 25a91a6 | 159 | // Package registry — npm protocol + UI (Block C2) |
| 160 | app.route("/", packagesApiRoutes); | |
| 161 | app.route("/", packagesUiRoutes); | |
| 162 | ||
| 163 | // Pages / static hosting (Block C3) | |
| 164 | app.route("/", pagesRoutes); | |
| 165 | ||
| 166 | // Environments with protected approvals (Block C4) | |
| 167 | app.route("/", environmentsRoutes); | |
| 168 | ||
| 3ef4c9d | 169 | // Insights + milestones |
| 170 | app.route("/", insightsRoutes); | |
| 171 | ||
| c81ab7a | 172 | // Explore page |
| 173 | app.route("/", exploreRoutes); | |
| 174 | ||
| 79136bb | 175 | // Web UI (catch-all, must be last) |
| 176 | app.route("/", webRoutes); | |
| 177 | ||
| 178 | // Global 404 | |
| 179 | app.notFound((c) => { | |
| 180 | return c.html( | |
| 181 | <Layout title="Not Found"> | |
| 182 | <div class="empty-state"> | |
| 183 | <h2>404</h2> | |
| 184 | <p>Page not found.</p> | |
| 185 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 186 | Go home | |
| 187 | </a> | |
| 188 | </div> | |
| 189 | </Layout>, | |
| 190 | 404 | |
| 191 | ); | |
| 192 | }); | |
| 193 | ||
| 194 | // Global error handler | |
| 195 | app.onError((err, c) => { | |
| 196 | console.error("[error]", err); | |
| 197 | return c.html( | |
| 198 | <Layout title="Error"> | |
| 199 | <div class="empty-state"> | |
| 200 | <h2>Something went wrong</h2> | |
| 201 | <p>An unexpected error occurred.</p> | |
| 202 | {process.env.NODE_ENV !== "production" && ( | |
| 203 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 204 | {err.message} | |
| 205 | </pre> | |
| 206 | )} | |
| 207 | </div> | |
| 208 | </Layout>, | |
| 209 | 500 | |
| 210 | ); | |
| 211 | }); | |
| 212 | ||
| 213 | export default app; |