You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
506 B

7 years ago
  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. };