aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-01-25 14:32:22 -0500
committerJoe Mou <dev@mou.fo>2026-01-25 17:46:15 -0500
commit20e72f96c814f298618091f9f1f37910a572be96 (patch)
treeeb2969cea10ed2a7dd5efd775f5c291cee63fa45 /src/index.ts
parent8547b87b120101803a989ac768e3ffba4785c451 (diff)
Support systemd socket activation
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/index.ts b/src/index.ts
index c934530..525ac74 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,4 +1,4 @@
-import { serve } from "@hono/node-server";
+import { createAdaptorServer, serve } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { Eta } from "eta";
import { Hono } from "hono";
@@ -55,7 +55,15 @@ app.get("/:owner/:repo/blob/:branch/:path{.*}", async (c) => {
}
});
-const port = parseInt(process.env.PORT || "3000", 10);
-serve({ fetch: app.fetch, port }, (info) => {
- console.log(`Server running on http://localhost:${info.port}`);
-});
+if (process.env.LISTEN_FDS === "1") {
+ const server = createAdaptorServer(app);
+ // Listen on SD_LISTEN_FDS_START.
+ 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}`);
+ });
+}