arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/node_modules/express/lib/middleware/query.js
node_modules/express/lib/middleware/query.jsRaw
 1/*!
 2 * express
 3 * Copyright(c) 2009-2013 TJ Holowaychuk
 4 * Copyright(c) 2013 Roman Shtylman
 5 * Copyright(c) 2014-2015 Douglas Christopher Wilson
 6 * MIT Licensed
 7 */
 8
 9'use strict';
10
11/**
12 * Module dependencies.
13 */
14
15var parseUrl = require('parseurl');
16var qs = require('qs');
17
18/**
19 * @param {Object} options
20 * @return {Function}
21 * @api public
22 */
23
24module.exports = function query(options) {
25  var opts = Object.create(options || null);
26  var queryparse = qs.parse;
27
28  if (typeof options === 'function') {
29    queryparse = options;
30    opts = undefined;
31  }
32
33  if (opts !== undefined && opts.allowPrototypes === undefined) {
34    // back-compat for qs module
35    opts.allowPrototypes = true;
36  }
37
38  return function query(req, res, next){
39    if (!req.query) {
40      var val = parseUrl(req).query;
41      req.query = queryparse(val, opts);
42    }
43
44    next();
45  };
46};