Files
horizon-airdef/website/serve.mjs
T
Ludovic Marie e936e412ba Website: the hub (/hub) with the roadmap, a Simple / Technical switch and live states
playhorizon.dev/hub is the public entry point to what is happening on Horizon. Overview: where
Horizon is, the 3 to 5 things in focus, what is next, what shipped last, how to help. Roadmap: Now /
Next / Later / Help wanted / Shipped, filtered by area, every item with its issues and pull requests
in their GitHub state (baked at build, refreshed in the browser). Contribute: good first tasks,
claiming, connecting an agent to Kira, the rules. A Simple / Technical switch swaps every item's
plain and dev text and is remembered. /roadmap redirects to the Roadmap tab.

tools/roadmap.py build now also writes website/data/roadmap.json, which the site reads and serves at
/hub/roadmap.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 15:57:46 +01:00

39 lines
1.8 KiB
JavaScript

// A dependency-free static server for dist/, for local checks (`npm run dev`).
// Railway uses Caddy instead (see Dockerfile).
import { createServer } from "node:http";
import { readFile, stat } from "node:fs/promises";
import { join, extname, normalize } from "node:path";
import { fileURLToPath } from "node:url";
const root = join(fileURLToPath(new URL(".", import.meta.url)), "dist");
const types = { ".html": "text/html; charset=utf-8", ".css": "text/css", ".js": "text/javascript", ".webp": "image/webp", ".png": "image/png", ".svg": "image/svg+xml", ".woff2": "font/woff2", ".txt": "text/plain; charset=utf-8", ".md": "text/plain; charset=utf-8", ".json": "application/json", ".xml": "application/xml" };
const port = Number(process.env.PORT) || 4173;
createServer(async (req, res) => {
let path = normalize(decodeURIComponent(new URL(req.url, "http://x").pathname)).replace(/^(\.\.[/\\])+/, "");
if (path.endsWith("/")) path += "index.html";
// The server guide is part of the docs now, as the Caddyfile redirects it.
if (path === "/server" || path === "/server.html") {
res.writeHead(301, { Location: "/docs/hosting" });
return res.end();
}
// The roadmap page became the hub's Roadmap tab.
if (path === "/roadmap") {
res.writeHead(301, { Location: "/hub#roadmap" });
return res.end();
}
if (path === "/docs") path = "/docs/index.html";
// /privacy and /docs/<page> are .html files, as the Caddyfile rewrites them.
if (!extname(path)) path += ".html";
let file = join(root, path);
let status = 200;
try {
if (!(await stat(file)).isFile()) throw 0;
} catch {
file = join(root, "404.html");
status = 404;
}
res.writeHead(status, { "Content-Type": types[extname(file)] || "application/octet-stream" });
res.end(await readFile(file));
}).listen(port, () => console.log(`http://localhost:${port}`));