uniapp,h5

server.js 998B

12345678910111213141516171819202122232425262728293031
  1. var http = require("http");
  2. var server = http.createServer(function (req, res) {
  3. switch (req.url) {
  4. case "/text":
  5. return res
  6. .writeHead(200, {"Content-Type": "text/plain"})
  7. .end("Hello world!");
  8. case "/xml":
  9. return res
  10. .writeHead(200, {"Content-Type": "application/xml"})
  11. .end("<element><child>Foobar</child></element>");
  12. case "/json":
  13. return res
  14. .writeHead(200, {"Content-Type": "application/json"})
  15. .end(JSON.stringify({ foo: "bar" }));
  16. case "/binary":
  17. return res
  18. .writeHead(200, {"Content-Type": "application/octet-stream"})
  19. .end(Buffer.from("Hello world!"));
  20. default:
  21. return res
  22. .writeHead(404, {"Content-Type": "text/plain"})
  23. .end("Not found");
  24. }
  25. }).listen(8888);
  26. process.on("SIGINT", function () {
  27. server.close();
  28. });