1
2/*!
3 * Connect - query
4 * Copyright(c) 2011 TJ Holowaychuk
5 * Copyright(c) 2011 Sencha Inc.
6 * MIT Licensed
7 */
8
9/**
10 * Module dependencies.
11 */
12
13var qs = require('qs')
14 , parse = require('url').parse;
15
16/**
17 * Automatically parse the query-string when available,
18 * populating the `req.query` object.
19 *
20 * Examples:
21 *
22 * connect(
23 * connect.query()
24 * , function(req, res){
25 * res.end(JSON.stringify(req.query));
26 * }
27 * ).listen(3000);
28 *
29 * @return {Function}
30 * @api public
31 */
32
33module.exports = function query(){
34 return function query(req, res, next){
35 req.query = ~req.url.indexOf('?')
36 ? qs.parse(parse(req.url).query)
37 : {};
38 next();
39 };
40};