var fs = require("fs"); var pathlib = require("path"); var webroot = "web"; var files = {}; function file(wpath, fpath) { if (typeof fpath === "object") return files[wpath] = fpath; if (fpath === undefined) fpath = wpath; files[wpath] = fs.readFileSync(pathlib.join(webroot, fpath)); } file("/polyfills.js"); file("/script.js"); file("/slide.css"); file("/slide.js"); file("/admin/", "/admin/index.html"); file("/admin/style.css"); file("/admin/lib.js"); file("/admin/view.js"); exports.canServe = canServe; function canServe(parts) { return files[parts.pathname] || files[parts.pathname + "/"]; } exports.serve = serve; function serve(parts, res) { var f = files[parts.pathname]; if (!f && files[parts.pathname + "/"]) { res.writeHead(302, { location: parts.pathname+"/" }); res.end(); } else { res.end(f); } }