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