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"; | |
| 4 | import { Layout } from "./views/layout"; | |
| 5 | import gitRoutes from "./routes/git"; | |
| 6 | import apiRoutes from "./routes/api"; | |
| 45e31d0 | 7 | import apiV2Routes from "./routes/api-v2"; |
| 8 | import apiDocsRoutes from "./routes/api-docs"; | |
| 79136bb | 9 | import authRoutes from "./routes/auth"; |
| 10 | import settingsRoutes from "./routes/settings"; | |
| 11 | import issueRoutes from "./routes/issues"; | |
| 12 | import repoSettings from "./routes/repo-settings"; | |
| 13 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 14 | import pullRoutes from "./routes/pulls"; |
| 15 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 16 | import forkRoutes from "./routes/fork"; |
| 17 | import webhookRoutes from "./routes/webhooks"; | |
| 18 | import exploreRoutes from "./routes/explore"; | |
| 19 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 20 | import contributorRoutes from "./routes/contributors"; |
| 59b6fb2 | 21 | import notificationRoutes from "./routes/notifications"; |
| 22 | import orgRoutes from "./routes/orgs"; | |
| 23 | import onboardingRoutes from "./routes/onboarding"; | |
| 79136bb | 24 | import webRoutes from "./routes/web"; |
| 59b6fb2 | 25 | import { authRateLimit, gitRateLimit, searchRateLimit } from "./middleware/rate-limit"; |
| 26 | import { csrfToken, csrfProtect } from "./middleware/csrf"; | |
| 79136bb | 27 | |
| 28 | const app = new Hono(); | |
| 29 | ||
| 30 | // Middleware | |
| 31 | app.use("*", logger()); | |
| 32 | app.use("/api/*", cors()); | |
| 33 | ||
| 59b6fb2 | 34 | // CSRF protection — set token on all requests, validate on mutations |
| 35 | app.use("*", csrfToken); | |
| 36 | app.use("*", csrfProtect); | |
| 37 | ||
| 45e31d0 | 38 | // Rate limit auth routes |
| 39 | app.use("/login", authRateLimit); | |
| 40 | app.use("/register", authRateLimit); | |
| 41 | ||
| 59b6fb2 | 42 | // Rate limit git operations |
| 43 | app.use("/:owner/:repo.git/*", gitRateLimit); | |
| 44 | ||
| 45 | // Rate limit search | |
| 46 | app.use("/:owner/:repo/search", searchRateLimit); | |
| 47 | app.use("/explore", searchRateLimit); | |
| 48 | ||
| 79136bb | 49 | // Git Smart HTTP protocol routes (must be before web routes) |
| 50 | app.route("/", gitRoutes); | |
| 51 | ||
| 45e31d0 | 52 | // REST API v1 (legacy) |
| 79136bb | 53 | app.route("/", apiRoutes); |
| 54 | ||
| 45e31d0 | 55 | // REST API v2 (comprehensive, token-authenticated) |
| 56 | app.route("/", apiV2Routes); | |
| 57 | ||
| 58 | // API documentation | |
| 59 | app.route("/", apiDocsRoutes); | |
| 60 | ||
| 79136bb | 61 | // Auth routes (register, login, logout) |
| 62 | app.route("/", authRoutes); | |
| 63 | ||
| 64 | // Settings routes (profile, SSH keys) | |
| 65 | app.route("/", settingsRoutes); | |
| 66 | ||
| c81ab7a | 67 | // API tokens |
| 68 | app.route("/", tokenRoutes); | |
| 69 | ||
| 59b6fb2 | 70 | // Notifications |
| 71 | app.route("/", notificationRoutes); | |
| 72 | ||
| 73 | // Organizations | |
| 74 | app.route("/", orgRoutes); | |
| 75 | ||
| 79136bb | 76 | // Repo settings (description, visibility, delete) |
| 77 | app.route("/", repoSettings); | |
| 78 | ||
| c81ab7a | 79 | // Webhooks management |
| 80 | app.route("/", webhookRoutes); | |
| 81 | ||
| 79136bb | 82 | // Compare view (branch diffs) |
| 83 | app.route("/", compareRoutes); | |
| 84 | ||
| 85 | // Issue tracker | |
| 86 | app.route("/", issueRoutes); | |
| 87 | ||
| 0074234 | 88 | // Pull requests |
| 89 | app.route("/", pullRoutes); | |
| 90 | ||
| c81ab7a | 91 | // Fork |
| 92 | app.route("/", forkRoutes); | |
| 93 | ||
| 0074234 | 94 | // Web file editor |
| 95 | app.route("/", editorRoutes); | |
| 96 | ||
| 43de941 | 97 | // Contributors |
| 98 | app.route("/", contributorRoutes); | |
| 99 | ||
| c81ab7a | 100 | // Explore page |
| 101 | app.route("/", exploreRoutes); | |
| 102 | ||
| 59b6fb2 | 103 | // Onboarding |
| 104 | app.route("/", onboardingRoutes); | |
| 105 | ||
| 79136bb | 106 | // Web UI (catch-all, must be last) |
| 107 | app.route("/", webRoutes); | |
| 108 | ||
| 109 | // Global 404 | |
| 110 | app.notFound((c) => { | |
| 111 | return c.html( | |
| 112 | <Layout title="Not Found"> | |
| 113 | <div class="empty-state"> | |
| 114 | <h2>404</h2> | |
| 115 | <p>Page not found.</p> | |
| 116 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 117 | Go home | |
| 118 | </a> | |
| 119 | </div> | |
| 120 | </Layout>, | |
| 121 | 404 | |
| 122 | ); | |
| 123 | }); | |
| 124 | ||
| 125 | // Global error handler | |
| 126 | app.onError((err, c) => { | |
| 127 | console.error("[error]", err); | |
| 128 | return c.html( | |
| 129 | <Layout title="Error"> | |
| 130 | <div class="empty-state"> | |
| 131 | <h2>Something went wrong</h2> | |
| 132 | <p>An unexpected error occurred.</p> | |
| 133 | {process.env.NODE_ENV !== "production" && ( | |
| 134 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 135 | {err.message} | |
| 136 | </pre> | |
| 137 | )} | |
| 138 | </div> | |
| 139 | </Layout>, | |
| 140 | 500 | |
| 141 | ); | |
| 142 | }); | |
| 143 | ||
| 144 | export default app; |