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"; |
| 6 | import gitRoutes from "./routes/git"; | |
| 7 | import apiRoutes from "./routes/api"; | |
| 8 | import authRoutes from "./routes/auth"; | |
| 9 | import settingsRoutes from "./routes/settings"; | |
| 10 | import issueRoutes from "./routes/issues"; | |
| 11 | import repoSettings from "./routes/repo-settings"; | |
| 12 | import compareRoutes from "./routes/compare"; | |
| 0074234 | 13 | import pullRoutes from "./routes/pulls"; |
| 14 | import editorRoutes from "./routes/editor"; | |
| c81ab7a | 15 | import forkRoutes from "./routes/fork"; |
| 16 | import webhookRoutes from "./routes/webhooks"; | |
| 17 | import exploreRoutes from "./routes/explore"; | |
| 18 | import tokenRoutes from "./routes/tokens"; | |
| 43de941 | 19 | import contributorRoutes from "./routes/contributors"; |
| 79136bb | 20 | import webRoutes from "./routes/web"; |
| 21 | ||
| 22 | const app = new Hono(); | |
| 23 | ||
| 05b973e | 24 | // Middleware — compression first (wraps all responses) |
| 25 | app.use("*", compress()); | |
| 26 | // Logger only on non-git routes to avoid overhead on clone/push | |
| 27 | app.use("*", async (c, next) => { | |
| 28 | if (c.req.path.includes(".git/")) return next(); | |
| 29 | return logger()(c, next); | |
| 30 | }); | |
| 79136bb | 31 | app.use("/api/*", cors()); |
| 32 | ||
| 33 | // Git Smart HTTP protocol routes (must be before web routes) | |
| 34 | app.route("/", gitRoutes); | |
| 35 | ||
| 36 | // REST API | |
| 37 | app.route("/", apiRoutes); | |
| 38 | ||
| 39 | // Auth routes (register, login, logout) | |
| 40 | app.route("/", authRoutes); | |
| 41 | ||
| 42 | // Settings routes (profile, SSH keys) | |
| 43 | app.route("/", settingsRoutes); | |
| 44 | ||
| c81ab7a | 45 | // API tokens |
| 46 | app.route("/", tokenRoutes); | |
| 47 | ||
| 79136bb | 48 | // Repo settings (description, visibility, delete) |
| 49 | app.route("/", repoSettings); | |
| 50 | ||
| c81ab7a | 51 | // Webhooks management |
| 52 | app.route("/", webhookRoutes); | |
| 53 | ||
| 79136bb | 54 | // Compare view (branch diffs) |
| 55 | app.route("/", compareRoutes); | |
| 56 | ||
| 57 | // Issue tracker | |
| 58 | app.route("/", issueRoutes); | |
| 59 | ||
| 0074234 | 60 | // Pull requests |
| 61 | app.route("/", pullRoutes); | |
| 62 | ||
| c81ab7a | 63 | // Fork |
| 64 | app.route("/", forkRoutes); | |
| 65 | ||
| 0074234 | 66 | // Web file editor |
| 67 | app.route("/", editorRoutes); | |
| 68 | ||
| 43de941 | 69 | // Contributors |
| 70 | app.route("/", contributorRoutes); | |
| 71 | ||
| c81ab7a | 72 | // Explore page |
| 73 | app.route("/", exploreRoutes); | |
| 74 | ||
| 79136bb | 75 | // Web UI (catch-all, must be last) |
| 76 | app.route("/", webRoutes); | |
| 77 | ||
| 78 | // Global 404 | |
| 79 | app.notFound((c) => { | |
| 80 | return c.html( | |
| 81 | <Layout title="Not Found"> | |
| 82 | <div class="empty-state"> | |
| 83 | <h2>404</h2> | |
| 84 | <p>Page not found.</p> | |
| 85 | <a href="/" style="margin-top: 12px; display: inline-block"> | |
| 86 | Go home | |
| 87 | </a> | |
| 88 | </div> | |
| 89 | </Layout>, | |
| 90 | 404 | |
| 91 | ); | |
| 92 | }); | |
| 93 | ||
| 94 | // Global error handler | |
| 95 | app.onError((err, c) => { | |
| 96 | console.error("[error]", err); | |
| 97 | return c.html( | |
| 98 | <Layout title="Error"> | |
| 99 | <div class="empty-state"> | |
| 100 | <h2>Something went wrong</h2> | |
| 101 | <p>An unexpected error occurred.</p> | |
| 102 | {process.env.NODE_ENV !== "production" && ( | |
| 103 | <pre style="margin-top: 16px; text-align: left; font-size: 12px; color: var(--red)"> | |
| 104 | {err.message} | |
| 105 | </pre> | |
| 106 | )} | |
| 107 | </div> | |
| 108 | </Layout>, | |
| 109 | 500 | |
| 110 | ); | |
| 111 | }); | |
| 112 | ||
| 113 | export default app; |