Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
885 bytes
|
Line | |
---|
1 | /*!
|
---|
2 | * express
|
---|
3 | * Copyright(c) 2009-2013 TJ Holowaychuk
|
---|
4 | * Copyright(c) 2013 Roman Shtylman
|
---|
5 | * Copyright(c) 2014-2015 Douglas Christopher Wilson
|
---|
6 | * MIT Licensed
|
---|
7 | */
|
---|
8 |
|
---|
9 | 'use strict';
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Module dependencies.
|
---|
13 | */
|
---|
14 |
|
---|
15 | var merge = require('utils-merge')
|
---|
16 | var parseUrl = require('parseurl');
|
---|
17 | var qs = require('qs');
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @param {Object} options
|
---|
21 | * @return {Function}
|
---|
22 | * @api public
|
---|
23 | */
|
---|
24 |
|
---|
25 | module.exports = function query(options) {
|
---|
26 | var opts = merge({}, options)
|
---|
27 | var queryparse = qs.parse;
|
---|
28 |
|
---|
29 | if (typeof options === 'function') {
|
---|
30 | queryparse = options;
|
---|
31 | opts = undefined;
|
---|
32 | }
|
---|
33 |
|
---|
34 | if (opts !== undefined && opts.allowPrototypes === undefined) {
|
---|
35 | // back-compat for qs module
|
---|
36 | opts.allowPrototypes = true;
|
---|
37 | }
|
---|
38 |
|
---|
39 | return function query(req, res, next){
|
---|
40 | if (!req.query) {
|
---|
41 | var val = parseUrl(req).query;
|
---|
42 | req.query = queryparse(val, opts);
|
---|
43 | }
|
---|
44 |
|
---|
45 | next();
|
---|
46 | };
|
---|
47 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.