waigo
Version:
Node.js ES6 framework for reactive, data-driven apps and APIs (Koa, RethinkDB)
36 lines (27 loc) • 904 B
JavaScript
const bodyParser = require('co-body'),
path = require('path');
const waigo = global.waigo,
_ = waigo._;
/**
* Build middleware for parsing request bodies.
*
* This middleware uses [co-body](https://github.com/visionmedia/co-body) to
* parse request POST bodies. Once parsed the request body parameters are
* available in `this.request.body`.
*
* If `csrf` middleware is enabled is set then this validates the csrf.
*
* @param {Object} options Configuration options for `co-body`.
* @param {String} [options.limit] The maximum allowed size of a request body.
*
* @return {Function} middleware
*/
var fn = module.exports = function(options) {
return function*(next) {
this.request.body = yield fn._bodyParser(this, options);
yield next;
};
};
// we attach actual parser to the function to make unit testing easier
fn._bodyParser = require('co-body');
;