arnaucube
arnaucube/raspberryGPIOhtmlserverPublic Self-hosted repository
raspberryGPIOhtmlserver/node_modules/connect/lib/middleware/query.js
node_modules/connect/lib/middleware/query.jsRaw
 1/*!
 2 * Connect - query
 3 * Copyright(c) 2011 TJ Holowaychuk
 4 * Copyright(c) 2011 Sencha Inc.
 5 * MIT Licensed
 6 */
 7
 8/**
 9 * Module dependencies.
10 */
11
12var qs = require('qs')
13  , parse = require('../utils').parseUrl;
14
15/**
16 * Query:
17 *
18 * Automatically parse the query-string when available,
19 * populating the `req.query` object.
20 *
21 * Examples:
22 *
23 *     connect()
24 *       .use(connect.query())
25 *       .use(function(req, res){
26 *         res.end(JSON.stringify(req.query));
27 *       });
28 *
29 *  The `options` passed are provided to qs.parse function.
30 *
31 * @param {Object} options
32 * @return {Function}
33 * @api public
34 */
35
36module.exports = function query(options){
37  return function query(req, res, next){
38    if (!req.query) {
39      req.query = ~req.url.indexOf('?')
40        ? qs.parse(parse(req).query, options)
41        : {};
42    }
43
44    next();
45  };
46};