summaryrefslogtreecommitdiff
path: root/cgithub/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cgithub/src/index.ts')
-rw-r--r--cgithub/src/index.ts42
1 files changed, 6 insertions, 36 deletions
diff --git a/cgithub/src/index.ts b/cgithub/src/index.ts
index 525ac74..fcd0069 100644
--- a/cgithub/src/index.ts
+++ b/cgithub/src/index.ts
@@ -14,45 +14,15 @@ const eta = new Eta({ views: path.join(__dirname, "..", "views") });
app.use("/static/*", serveStatic({ root: path.join(__dirname, "..") }));
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 { owner, repo, branch, path = "" } = c.req.param();
+ const data = await getGitHubTree(owner, repo, branch, path);
+ return c.html(await eta.renderAsync("tree.eta", data));
});
app.get("/:owner/:repo/blob/: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 getGitHubBlob(owner, repo, branch, path);
- const html = await eta.renderAsync("blob.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 { owner, repo, branch, path } = c.req.param();
+ const data = await getGitHubBlob(owner, repo, branch, path);
+ return c.html(await eta.renderAsync("blob.eta", data));
});
if (process.env.LISTEN_FDS === "1") {