@@ -90,6 +90,11 @@ In the future, it will be possible to control the logging level. | |||
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]) | |||
Serve static files. |
@@ -12,6 +12,13 @@ function template(tpml, args) { | |||
return tpml; | |||
} | |||
function resJson(obj) { | |||
res.writeHead(200, { | |||
"content-type": "application/json" | |||
}); | |||
this.end(JSON.stringify(obj)); | |||
} | |||
class App { | |||
constructor(options) { | |||
options = options || {}; | |||
@@ -55,6 +62,7 @@ class App { | |||
// Listen for requests | |||
this.server.on("request", (req, res) => { | |||
res.json = resJson; | |||
var url = urllib.parse(req.url); | |||
req.urlobj = url; | |||
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "webframe", | |||
"version": "0.1.4", | |||
"version": "0.2.0", | |||
"description": "Web server.", | |||
"main": "index.js", | |||
"scripts": { |