summaryrefslogtreecommitdiff
path: root/cgithub/src/index.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-01-22 13:27:36 -0500
committerJoe Mou <dev@mou.fo>2026-01-23 00:54:48 -0500
commitd0dccc7a910a579d8c172c3d5a5a02ea3abd964d (patch)
treed10be3141653130f6e89cbdf0181c2e1ec07dd82 /cgithub/src/index.ts
parent5e45f900974589c8eead15fc352d50dc45b1a25a (diff)
Simple web server for viewing trees
Diffstat (limited to 'cgithub/src/index.ts')
-rw-r--r--cgithub/src/index.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/cgithub/src/index.ts b/cgithub/src/index.ts
new file mode 100644
index 0000000..df0a116
--- /dev/null
+++ b/cgithub/src/index.ts
@@ -0,0 +1,36 @@
+import { Hono } from "hono";
+import { serve } from "@hono/node-server";
+import { serveStatic } from "@hono/node-server/serve-static";
+import { Eta } from "eta";
+import { getGitHubTree } from "./scraper.js";
+
+const app = new Hono();
+const eta = new Eta({ views: "./views" });
+
+app.use("/static/*", serveStatic({ root: "." }));
+
+app.get("/:owner/:repo/tree/:branch/:path{.*}?", async (c) => {
+ try {
+ const owner = c.req.param("owner");
+ const repo = c.req.param("repo");
+ const branch = c.req.param("branch");
+ const path = c.req.param("path") || "";
+
+ const data = await getGitHubTree(owner, repo, branch, path);
+ const html = await eta.renderAsync("tree.eta", data);
+
+ return c.html(html);
+ } catch (error) {
+ const errorMessage =
+ error instanceof Error ? error.message : "Unknown error";
+ return c.html(
+ `<html><body><h1>Error</h1><p>${errorMessage}</p></body></html>`,
+ 500,
+ );
+ }
+});
+
+const port = parseInt(process.env.PORT || "3000", 10);
+serve({ fetch: app.fetch, port }, (info) => {
+ console.log(`Server running on http://localhost:${info.port}`);
+});