12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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);
- }
- }
|