1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var _ = require('lodash');
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function RouteParamsHandler() {
|
17 |
|
18 | }
|
19 |
|
20 | RouteParamsHandler.prototype.mapRequest = function(context, callback) {
|
21 | if (_.isNil(context.request)) {
|
22 | return callback();
|
23 | }
|
24 | else if (_.isNil(context.request.route)) {
|
25 | return callback();
|
26 | }
|
27 | else {
|
28 | var route=context.request.route;
|
29 |
|
30 | context.params = context.params || {};
|
31 | if (typeof route.params === 'object' && route.params!==null) {
|
32 | var keys = Object.keys(route.params);
|
33 | keys.forEach(function(key) { context.params[key] = route.params[key] });
|
34 | }
|
35 | return callback();
|
36 | }
|
37 | };
|
38 |
|
39 | if (typeof exports !== 'undefined') {
|
40 | module.exports.createInstance = function() { return new RouteParamsHandler(); };
|
41 | }
|