// Simple local dev server — serves frontend on http://localhost:3000 // Usage: node serve.js (uses config.js — points to deployed API) // node serve.js --local (uses config.local.js — points to SAM local on :3001) const http = require("http"); const fs = require("fs"); const path = require("path"); const PORT = 3000; const DIR = __dirname; const LOCAL_MODE = process.argv.includes("--local"); const MIME = { ".html": "text/html", ".js": "application/javascript", ".css": "text/css", ".json": "application/json", ".png": "image/png", ".svg": "image/svg+xml", ".ico": "image/x-icon", }; http.createServer((req, res) => { let url = req.url.split("?")[0]; if (url === "/") url = "/login.html"; // In local mode, serve config.local.js when config.js is requested if (LOCAL_MODE && url === "/config.js") { url = "/config.local.js"; } const filePath = path.join(DIR, url); const ext = path.extname(filePath); fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404); res.end("Not found"); return; } res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" }); res.end(data); }); }).listen(PORT, () => { const mode = LOCAL_MODE ? "LOCAL (API → localhost:3001)" : "DEPLOYED (API → production)"; console.log(`\n LedgerFlow frontend: http://localhost:${PORT} [${mode}]\n`); });