Pictures!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var fs = require("fs");
  2. var pathlib = require("path");
  3. var webroot = "web";
  4. var files = {};
  5. function file(wpath, fpath) {
  6. if (typeof fpath === "object")
  7. return files[wpath] = fpath;
  8. if (fpath === undefined)
  9. fpath = wpath;
  10. files[wpath] = fs.readFileSync(pathlib.join(webroot, fpath));
  11. }
  12. file("/polyfills.js");
  13. file("/script.js");
  14. file("/slide.css");
  15. file("/slide.js");
  16. file("/admin/", "/admin/index.html");
  17. file("/admin/style.css");
  18. file("/admin/lib.js");
  19. file("/admin/view.js");
  20. exports.canServe = canServe;
  21. function canServe(parts) {
  22. return files[parts.pathname] || files[parts.pathname + "/"];
  23. }
  24. exports.serve = serve;
  25. function serve(parts, res) {
  26. var f = files[parts.pathname];
  27. if (!f && files[parts.pathname + "/"]) {
  28. res.writeHead(302, {
  29. location: parts.pathname+"/"
  30. });
  31. res.end();
  32. } else {
  33. res.end(f);
  34. }
  35. }