Mercurial > hg > nodescore
comparison node_modules/express/lib/middleware/query.js @ 73:0c3a2942ddee
now using express to server static content
author | Rob Canning <rc@kiben.net> |
---|---|
date | Sun, 29 Jun 2014 12:11:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
72:9af4250ff7d5 | 73:0c3a2942ddee |
---|---|
1 /** | |
2 * Module dependencies. | |
3 */ | |
4 | |
5 var qs = require('qs'); | |
6 var parseUrl = require('parseurl'); | |
7 | |
8 /** | |
9 * Query: | |
10 * | |
11 * Automatically parse the query-string when available, | |
12 * populating the `req.query` object using | |
13 * [qs](https://github.com/visionmedia/node-querystring). | |
14 * | |
15 * Examples: | |
16 * | |
17 * .use(connect.query()) | |
18 * .use(function(req, res){ | |
19 * res.end(JSON.stringify(req.query)); | |
20 * }); | |
21 * | |
22 * The `options` passed are provided to qs.parse function. | |
23 * | |
24 * @param {Object} options | |
25 * @return {Function} | |
26 * @api public | |
27 */ | |
28 | |
29 module.exports = function query(options){ | |
30 return function query(req, res, next){ | |
31 if (!req.query) { | |
32 req.query = ~req.url.indexOf('?') | |
33 ? qs.parse(parseUrl(req).query, options) | |
34 : {}; | |
35 } | |
36 | |
37 next(); | |
38 }; | |
39 }; |