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