In the future, there will be middleware for POST request too. | In the future, there will be middleware for POST request too. | ||||
### Modifications to the request and response objects | |||||
* `req.urlobj`: The result of `url.parse(req.url)`. | |||||
* `res.json(object)`: A utility function to respond with JSON. | |||||
### webframe.static(root[, before]) | ### webframe.static(root[, before]) | ||||
Serve static files. | Serve static files. |
return tpml; | return tpml; | ||||
} | } | ||||
function resJson(obj) { | |||||
res.writeHead(200, { | |||||
"content-type": "application/json" | |||||
}); | |||||
this.end(JSON.stringify(obj)); | |||||
} | |||||
class App { | class App { | ||||
constructor(options) { | constructor(options) { | ||||
options = options || {}; | options = options || {}; | ||||
// Listen for requests | // Listen for requests | ||||
this.server.on("request", (req, res) => { | this.server.on("request", (req, res) => { | ||||
res.json = resJson; | |||||
var url = urllib.parse(req.url); | var url = urllib.parse(req.url); | ||||
req.urlobj = url; | req.urlobj = url; | ||||
{ | { | ||||
"name": "webframe", | "name": "webframe", | ||||
"version": "0.1.4", | |||||
"version": "0.2.0", | |||||
"description": "Web server.", | "description": "Web server.", | ||||
"main": "index.js", | "main": "index.js", | ||||
"scripts": { | "scripts": { |