blob: df0a116b1844f7150240d63f89d5cf04419c80f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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}`);
});
|