Merge "LOG SQL dump files getting installed"
[sdnc/oam.git] / dgbuilder / dgeflows / node_modules / body-parser / index.js
1 /*!
2  * body-parser
3  * Copyright(c) 2014 Douglas Christopher Wilson
4  * MIT Licensed
5  */
6
7 /**
8  * Module dependencies.
9  */
10
11 var deprecate = require('depd')('body-parser')
12 var fs = require('fs')
13 var path = require('path')
14
15 /**
16  * @typedef Parsers
17  * @type {function}
18  * @property {function} json
19  * @property {function} raw
20  * @property {function} text
21  * @property {function} urlencoded
22  */
23
24 /**
25  * Module exports.
26  * @type {Parsers}
27  */
28
29 exports = module.exports = deprecate.function(bodyParser,
30   'bodyParser: use individual json/urlencoded middlewares')
31
32 /**
33  * Path to the parser modules.
34  */
35
36 var parsersDir = path.join(__dirname, 'lib', 'types')
37
38 /**
39  * Auto-load bundled parsers with getters.
40  */
41
42 fs.readdirSync(parsersDir).forEach(function onfilename(filename) {
43   if (!/\.js$/.test(filename)) return
44
45   var loc = path.resolve(parsersDir, filename)
46   var mod
47   var name = path.basename(filename, '.js')
48
49   function load() {
50     if (mod) {
51       return mod
52     }
53
54     return mod = require(loc)
55   }
56
57   Object.defineProperty(exports, name, {
58     configurable: true,
59     enumerable: true,
60     get: load
61   })
62 })
63
64 /**
65  * Create a middleware to parse json and urlencoded bodies.
66  *
67  * @param {object} [options]
68  * @return {function}
69  * @deprecated
70  * @api public
71  */
72
73 function bodyParser(options){
74   var opts = {}
75
76   options = options || {}
77
78   // exclude type option
79   for (var prop in options) {
80     if ('type' !== prop) {
81       opts[prop] = options[prop]
82     }
83   }
84
85   var _urlencoded = exports.urlencoded(opts)
86   var _json = exports.json(opts)
87
88   return function bodyParser(req, res, next) {
89     _json(req, res, function(err){
90       if (err) return next(err);
91       _urlencoded(req, res, next);
92     });
93   }
94 }