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