Browse Source

added res.json() function

master
mortie 7 years ago
parent
commit
8b413a4269
3 changed files with 14 additions and 1 deletions
  1. 5
    0
      README.md
  2. 8
    0
      index.js
  3. 1
    1
      package.json

+ 5
- 0
README.md View File



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.

+ 8
- 0
index.js View File

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;



+ 1
- 1
package.json View File

{ {
"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": {

Loading…
Cancel
Save