SPB Git forge

spb/draft2027

Public
1commits 1branches 0releases
92.0 KBsize
maindefault branch
19 days agolast push
HTML 99% JavaScript 1%
1.4 KB · 28 lines javascript
Raw Blame History
1// DraftVision 2027 — serveur statique zéro dépendance2// Auteur : Simon-Pierre Boucher — contact@spboucher.ai3// Usage : node server.mjs [port]   (défaut 8100) · healthcheck : /healthz4import { createServer } from "node:http";5import { readFile } from "node:fs/promises";6import { extname, join, normalize } from "node:path";7import { fileURLToPath } from "node:url";89const PORT = Number(process.argv[2]) || 8100;10const RACINE = fileURLToPath(new URL(".", import.meta.url));11const TYPES = { ".html":"text/html; charset=utf-8", ".md":"text/markdown; charset=utf-8",12  ".png":"image/png", ".ico":"image/x-icon", ".txt":"text/plain; charset=utf-8" };1314createServer(async (req, res) => {15  const url = new URL(req.url, "http://x");16  if (url.pathname === "/healthz") { res.writeHead(200, {"Content-Type":"application/json"}); return res.end('{"ok":true,"app":"draftvision2027"}'); }17  let chemin = url.pathname === "/" ? "/index.html" : url.pathname;18  chemin = normalize(chemin).replace(/^(\.\.[/\\])+/, "");19  try {20    const donnees = await readFile(join(RACINE, chemin));21    res.writeHead(200, {"Content-Type": TYPES[extname(chemin)] || "application/octet-stream", "Cache-Control":"no-cache"});22    res.end(donnees);23  } catch {24    res.writeHead(404, {"Content-Type":"text/plain; charset=utf-8"});25    res.end("404 — introuvable");26  }27}).listen(PORT, "0.0.0.0", () => console.log(`DraftVision 2027 sur http://0.0.0.0:${PORT}`));28