2026-04-02 18:19:49 -04:00
|
|
|
// Simple local dev server — serves frontend on http://localhost:3000
|
2026-04-03 13:58:28 -04:00
|
|
|
// 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)
|
2026-04-02 18:19:49 -04:00
|
|
|
|
|
|
|
|
const http = require("http");
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
|
|
const PORT = 3000;
|
|
|
|
|
const DIR = __dirname;
|
2026-04-03 13:58:28 -04:00
|
|
|
const LOCAL_MODE = process.argv.includes("--local");
|
2026-04-02 18:19:49 -04:00
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
2026-04-03 13:58:28 -04:00
|
|
|
// In local mode, serve config.local.js when config.js is requested
|
|
|
|
|
if (LOCAL_MODE && url === "/config.js") {
|
|
|
|
|
url = "/config.local.js";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-02 18:19:49 -04:00
|
|
|
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, () => {
|
2026-04-03 13:58:28 -04:00
|
|
|
const mode = LOCAL_MODE ? "LOCAL (API → localhost:3001)" : "DEPLOYED (API → production)";
|
|
|
|
|
console.log(`\n LedgerFlow frontend: http://localhost:${PORT} [${mode}]\n`);
|
2026-04-02 18:19:49 -04:00
|
|
|
});
|