From fd41d9ca279caf6cf5b3edc0b873a36b0533a215 Mon Sep 17 00:00:00 2001 From: Natalie Date: Sun, 26 Apr 2026 15:06:26 -0700 Subject: [PATCH] =?UTF-8?q?feat(@projects/@magic-civilization):=20?= =?UTF-8?q?=E2=9C=A8=20add=20serve.js=20file=20for=20local=20design=20prev?= =?UTF-8?q?iew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .project/designs/serve.js | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 .project/designs/serve.js diff --git a/.project/designs/serve.js b/.project/designs/serve.js new file mode 100644 index 00000000..1b694e9b --- /dev/null +++ b/.project/designs/serve.js @@ -0,0 +1,77 @@ +#!/usr/bin/env node +const http = require("http"); +const fs = require("fs"); +const path = require("path"); + +const PORT = 7777; +const ROOT = __dirname; + +const MIME = { + ".html": "text/html", + ".css": "text/css", + ".js": "application/javascript", + ".json": "application/json", + ".png": "image/png", + ".svg": "image/svg+xml", + ".md": "text/plain", +}; + +http.createServer((req, res) => { + let urlPath = req.url === "/" ? "/index.html" : req.url; + // auto-serve directory listing if no index + if (urlPath === "/index.html" && !fs.existsSync(path.join(ROOT, "index.html"))) { + const files = fs.readdirSync(ROOT).filter(f => !f.startsWith(".") && f !== "serve.js"); + const links = files + .sort((a, b) => { + const aHtml = a.endsWith(".html"); + const bHtml = b.endsWith(".html"); + if (aHtml && !bHtml) return -1; + if (!aHtml && bHtml) return 1; + return a.localeCompare(b); + }) + .map(f => { + const isHtml = f.endsWith(".html"); + const icon = isHtml ? "๐Ÿ–ผ" : f.endsWith(".json") ? "๐Ÿ“‹" : f.endsWith(".md") ? "๐Ÿ“„" : "๐Ÿ“"; + return `
  • ${icon} ${f}
  • `; + }) + .join("\n"); + + res.writeHead(200, { "Content-Type": "text/html" }); + res.end(` + + + +Age of Dwarves โ€” Designs + + + + +

    Age of Dwarves

    +

    Design System ยท .project/designs/

    + + +`); + return; + } + + const filePath = path.join(ROOT, urlPath); + if (!filePath.startsWith(ROOT)) { res.writeHead(403); res.end(); return; } + + fs.readFile(filePath, (err, data) => { + if (err) { res.writeHead(404, { "Content-Type": "text/plain" }); res.end("Not found"); return; } + const ext = path.extname(filePath); + res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" }); + res.end(data); + }); +}).listen(PORT, () => { + console.log(`\n Age of Dwarves designs โ†’ http://localhost:${PORT}\n`); +});