query.js
This file
Path
lib/middleware/query.js
35 lines · 758 bytes · JavaScript
Last changed by
remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08
History of this fileTake it
remove last pieces of connect dependencyRoman Shtylmanbefore adoption1396e08
lines 1–35why, one step back1var qs = require('qs');2var parseUrl = require('../utils').parseUrl;34/**5 * Query:6 *7 * Automatically parse the query-string when available,8 * populating the `req.query` object using9 * [qs](https://github.com/visionmedia/node-querystring).10 *11 * Examples:12 *13 * .use(connect.query())14 * .use(function(req, res){15 * res.end(JSON.stringify(req.query));16 * });17 *18 * The `options` passed are provided to qs.parse function.19 *20 * @param {Object} options21 * @return {Function}22 * @api public23 */2425module.exports = function query(options){26 return function query(req, res, next){27 if (!req.query) {28 req.query = ~req.url.indexOf('?')29 ? qs.parse(parseUrl(req).query, options)30 : {};31 }3233 next();34 };35};