annotate node_modules/express/lib/middleware/query.js @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents 0c3a2942ddee
children
rev   line source
rc@73 1 /**
rc@73 2 * Module dependencies.
rc@73 3 */
rc@73 4
rc@73 5 var qs = require('qs');
rc@73 6 var parseUrl = require('parseurl');
rc@73 7
rc@73 8 /**
rc@73 9 * Query:
rc@73 10 *
rc@73 11 * Automatically parse the query-string when available,
rc@73 12 * populating the `req.query` object using
rc@73 13 * [qs](https://github.com/visionmedia/node-querystring).
rc@73 14 *
rc@73 15 * Examples:
rc@73 16 *
rc@73 17 * .use(connect.query())
rc@73 18 * .use(function(req, res){
rc@73 19 * res.end(JSON.stringify(req.query));
rc@73 20 * });
rc@73 21 *
rc@73 22 * The `options` passed are provided to qs.parse function.
rc@73 23 *
rc@73 24 * @param {Object} options
rc@73 25 * @return {Function}
rc@73 26 * @api public
rc@73 27 */
rc@73 28
rc@73 29 module.exports = function query(options){
rc@73 30 return function query(req, res, next){
rc@73 31 if (!req.query) {
rc@73 32 req.query = ~req.url.indexOf('?')
rc@73 33 ? qs.parse(parseUrl(req).query, options)
rc@73 34 : {};
rc@73 35 }
rc@73 36
rc@73 37 next();
rc@73 38 };
rc@73 39 };