3 * Copyright(c) 2014 Douglas Christopher Wilson
11 var deprecate = require('depd')('body-parser')
12 var fs = require('fs')
13 var path = require('path')
18 * @property {function} json
19 * @property {function} raw
20 * @property {function} text
21 * @property {function} urlencoded
29 exports = module.exports = deprecate.function(bodyParser,
30 'bodyParser: use individual json/urlencoded middlewares')
33 * Path to the parser modules.
36 var parsersDir = path.join(__dirname, 'lib', 'types')
39 * Auto-load bundled parsers with getters.
42 fs.readdirSync(parsersDir).forEach(function onfilename(filename) {
43 if (!/\.js$/.test(filename)) return
45 var loc = path.resolve(parsersDir, filename)
47 var name = path.basename(filename, '.js')
54 return mod = require(loc)
57 Object.defineProperty(exports, name, {
65 * Create a middleware to parse json and urlencoded bodies.
67 * @param {object} [options]
73 function bodyParser(options){
76 options = options || {}
78 // exclude type option
79 for (var prop in options) {
80 if ('type' !== prop) {
81 opts[prop] = options[prop]
85 var _urlencoded = exports.urlencoded(opts)
86 var _json = exports.json(opts)
88 return function bodyParser(req, res, next) {
89 _json(req, res, function(err){
90 if (err) return next(err);
91 _urlencoded(req, res, next);