Web framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example.js 914B

123456789101112131415161718192021222324
  1. // Replace with require("webframe")
  2. var webframe = require("./index.js");
  3. var mw = webframe.middleware;
  4. var app = new webframe.App();
  5. // Endpoint which uses the "params" middleware to parse URL parameters
  6. app.get("/params-example", [ mw.params ], (req, res) => {
  7. res.writeHead(200, { "Content-Type": "text/plain" });
  8. res.end("Hello, "+req.params.name);
  9. });
  10. // Endpoint which uses the "payload" middleware to get the payload as a string
  11. app.post("/payload-example", [ mw.payload ], (req, res) => {
  12. res.writeHead(200, { "Content-Type": "text/plain" });
  13. res.end(req.payload);
  14. });
  15. // When a an endpoint path starts with a ^, it's interpreted as a
  16. // regular expression pattern. "^.*" matches everything (though endpoints
  17. // with explicit paths, like the "/endpoint" above, are prioritized).
  18. //
  19. // webframe.staic("web") returns a function which serves the file in "web".
  20. app.get("^.*", webframe.static("web"));