query.js 506 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Module dependencies.
  3. */
  4. var parseUrl = require('parseurl');
  5. var qs = require('qs');
  6. /**
  7. * @param {Object} options
  8. * @return {Function}
  9. * @api public
  10. */
  11. module.exports = function query(options) {
  12. var queryparse = qs.parse;
  13. if (typeof options === 'function') {
  14. queryparse = options;
  15. options = undefined;
  16. }
  17. return function query(req, res, next){
  18. if (!req.query) {
  19. var val = parseUrl(req).query;
  20. req.query = queryparse(val, options);
  21. }
  22. next();
  23. };
  24. };