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