diff options
| author | Teddy Wing | 2014-10-30 20:27:55 -0400 | 
|---|---|---|
| committer | Teddy Wing | 2014-10-30 20:27:55 -0400 | 
| commit | fb4b26ac3aa96432fabeaa5b180690a7f5e3c981 (patch) | |
| tree | f3d9c7d231569417f72aab4e12b26d76e0cfed68 /node_modules/body-parser/index.js | |
| parent | 65600960507d714053d6c7ba99b8e3ced1d6761f (diff) | |
| download | sipping-point-fb4b26ac3aa96432fabeaa5b180690a7f5e3c981.tar.bz2 | |
Add node_modules/
Diffstat (limited to 'node_modules/body-parser/index.js')
| -rw-r--r-- | node_modules/body-parser/index.js | 84 | 
1 files changed, 84 insertions, 0 deletions
diff --git a/node_modules/body-parser/index.js b/node_modules/body-parser/index.js new file mode 100644 index 0000000..7c87204 --- /dev/null +++ b/node_modules/body-parser/index.js @@ -0,0 +1,84 @@ +/*! + * body-parser + * Copyright(c) 2014 Douglas Christopher Wilson + * MIT Licensed + */ + +/** + * Module dependencies. + */ + +var deprecate = require('depd')('body-parser') +var fs = require('fs') +var path = require('path') + +/** + * Module exports. + */ + +exports = module.exports = deprecate.function(bodyParser, +  'bodyParser: use individual json/urlencoded middlewares') + +/** + * Path to the parser modules. + */ + +var parsersDir = path.join(__dirname, 'lib', 'types') + +/** + * Auto-load bundled parsers with getters. + */ + +fs.readdirSync(parsersDir).forEach(function onfilename(filename) { +  if (!/\.js$/.test(filename)) return + +  var loc = path.resolve(parsersDir, filename) +  var mod +  var name = path.basename(filename, '.js') + +  function load() { +    if (mod) { +      return mod +    } + +    return mod = require(loc) +  } + +  Object.defineProperty(exports, name, { +    configurable: true, +    enumerable: true, +    get: load +  }) +}) + +/** + * Create a middleware to parse json and urlencoded bodies. + * + * @param {object} [options] + * @return {function} + * @deprecated + * @api public + */ + +function bodyParser(options){ +  var opts = {} + +  options = options || {} + +  // exclude type option +  for (var prop in options) { +    if ('type' !== prop) { +      opts[prop] = options[prop] +    } +  } + +  var _urlencoded = exports.urlencoded(opts) +  var _json = exports.json(opts) + +  return function bodyParser(req, res, next) { +    _json(req, res, function(err){ +      if (err) return next(err); +      _urlencoded(req, res, next); +    }); +  } +}  | 
