summaryrefslogtreecommitdiff
path: root/cgithub/src/index.ts
blob: 79f09d98b76a7972e4403255d9c2c0ed1606ecf6 (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
import { createAdaptorServer, serve } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { Eta } from "eta";
import { Hono } from "hono";
import path from "node:path";
import { createApp } from "./app.ts";

const root = path.join(import.meta.dirname, "..");
const eta = new Eta({ views: path.join(root, "views") });

const app = new Hono();
app.use("/static/*", serveStatic({ root: path.join(root, "public") }));
app.route("/", createApp(eta));

if (process.env.LISTEN_FDS === "1") {
  const server = createAdaptorServer(app);
  server.listen({ fd: 3 }, () => {
    console.log("Server running via systemd socket activation");
  });
} else {
  const port = parseInt(process.env.PORT || "3000", 10);
  serve({ fetch: app.fetch, port }, (info) => {
    console.log(`Server running on http://localhost:${info.port}`);
  });
}