Created
July 17, 2014 01:11
-
-
Save Raynos/f483d2d939ea13f23295 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonBody = require('body/json'); | |
/* usage | |
```js | |
router.addRoute('/foo/bar', | |
bodyParser(function (req, res, opts, cb))) | |
``` | |
using multiple "middlewares" | |
```js | |
router.addRoute('/foo/bar', | |
bodyParser( | |
getSession( | |
myRouteHandler | |
) | |
) | |
) | |
``` | |
using a sugar module | |
```js | |
var compose = require('composite'); | |
router.addRoute('/foo/bar', compose( | |
getSession, | |
bodyParser | |
)(myRouteHandler)) | |
``` | |
*/ | |
module.exports = bodyParser; | |
function bodyParser(handler) { | |
return function (req, res, opts, cb) { | |
jsonBody(req, res, function (err, body) { | |
if (err) { | |
return cb(err); | |
} | |
opts.body = body; | |
handler(req, res, opts, cb); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment