Проверить Matter.js
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

63 行
1.4KB

  1. const fs = require("fs");
  2. const http = require("http");
  3. const path = require("path");
  4. var jsonUpdates = {};
  5. const srv = http.createServer(process);
  6. srv.listen(8000);
  7. fs.watch(__dirname, trackJSONUpdates);
  8. function process(req, res)
  9. {
  10. var fileName = "." + decodeURI(req.url);
  11. if (fileName == "./")
  12. {
  13. fileName = "./index.html";
  14. }
  15. else if (fileName == "./json.js")
  16. {
  17. const content = Object.keys(jsonUpdates).sort().join("\n");
  18. jsonUpdates = {};
  19. res.writeHead(200, { "Content-Type": "text/javascript" });
  20. res.end(content, "utf-8");
  21. return;
  22. }
  23. console.debug("fileName:", fileName);
  24. const ext = path.extname(fileName);
  25. var contentType = "text/html";
  26. switch (ext)
  27. {
  28. case ".js":
  29. contentType = "text/javascript";
  30. break;
  31. case "png":
  32. contentType = "image/png";
  33. break;
  34. case "jpg":
  35. contentType = "image/jpg";
  36. break;
  37. }
  38. fs.readFile(fileName, function(err, content) {
  39. if (err)
  40. {
  41. res.writeHead(500);
  42. res.end(err.code);
  43. return;
  44. }
  45. res.writeHead(200, { "Content-Type": contentType });
  46. res.end(content, "utf-8");
  47. });
  48. }
  49. function trackJSONUpdates(eventName, fileName)
  50. {
  51. if (!fileName.endsWith("json.js"))
  52. {
  53. return;
  54. }
  55. jsonUpdates[fileName] = true;
  56. console.debug("fileName", fileName);
  57. }