Comparing version 4.1.1 to 4.2.1
@@ -22,2 +22,6 @@ var TypedError = require("error/typed") | ||
if (!callback) { | ||
return anyBody.bind(null, req, res, opts) | ||
} | ||
var contentType = req.headers["content-type"] || "" | ||
@@ -24,0 +28,0 @@ |
@@ -13,2 +13,6 @@ var querystringParse = require("querystring").parse | ||
if (!callback) { | ||
return formBody.bind(null, req, res, opts) | ||
} | ||
var parse = opts.querystring ? opts.querystring.parse : querystringParse | ||
@@ -15,0 +19,0 @@ |
@@ -13,2 +13,6 @@ var rawBody = require("raw-body") | ||
if (!callback) { | ||
return body.bind(null, req, res, opts) | ||
} | ||
var limit = "limit" in opts ? opts.limit : ONE_MB | ||
@@ -15,0 +19,0 @@ var contentLength = Number(req.headers["content-length"] || "") |
@@ -12,2 +12,6 @@ var body = require("./index") | ||
if (!callback) { | ||
return jsonBody.bind(null, req, res, opts) | ||
} | ||
var parse = opts.JSON ? opts.JSON.parse : jsonParse | ||
@@ -14,0 +18,0 @@ var reviver = opts.reviver || null |
{ | ||
"name": "body", | ||
"version": "4.1.1", | ||
"version": "4.2.1", | ||
"description": "Body parsing", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -38,2 +38,48 @@ # body [![build status][1]][2] | ||
## Example generators | ||
You can use `body` with generators as the body functions will | ||
return a continuable if you don't pass a callback. | ||
```js | ||
var http = require("http") | ||
var Router = require("routes-router") | ||
var jsonBody = require("body/json") | ||
var formBody = require("body/form") | ||
// async turns a generator into an async function taking a cb | ||
var async = require("gens") | ||
// the router works with normal async functions. | ||
// router automatically handles errors as 500 responses | ||
var app = Router({ | ||
// do whatever you want. the jsonBody error would go here | ||
errorHandler: function (req, res, err) { | ||
res.statusCode = 500 | ||
res.end(err.message) | ||
} | ||
}) | ||
app.addRoute("/json", async(function* (req, res) { | ||
// if jsonBody has an error it just goes to the cb | ||
// in the called in the router. and it does the correct thing | ||
// it shows your 500 page. | ||
var body = yield jsonBody(req, res) | ||
res.setHeader("content-type", "application/json") | ||
res.end(JSON.stringify(body)) | ||
})) | ||
app.addRoute("/form", async(function* (req, res) { | ||
var body = yield formBody(req, res) | ||
res.setHeader("content-type", "application/json") | ||
res.end(JSON.stringify(body)) | ||
})) | ||
// app returned from the router is just a function(req, res) {} | ||
// that dispatches the req/res to the correct route based on | ||
// the routers routing table & req.url | ||
http.createServer(app).listen(8080) | ||
``` | ||
## Documentation | ||
@@ -40,0 +86,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14953
172
294