1
0
Fork 0

Converted req.path into a method (no longer useless).

This commit is contained in:
Alan Plum 2015-05-07 01:19:03 +02:00
parent bd09144970
commit de97cfa5fb
1 changed files with 18 additions and 2 deletions

View File

@ -970,7 +970,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) {
result = result.concat(flattenRouting(
parameter.match,
path + "/<parameters>",
path + "/:" + parameter.parameter,
cur,
newUrlParameters,
depth + 1,
@ -1009,7 +1009,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) {
if (routes.hasOwnProperty('prefix')) {
result = result.concat(flattenRouting(
routes.prefix,
path + "/...",
path + "/*",
rexpr + "(/[^/]+)*/?",
urlParameters._shallowCopy,
depth + 1,
@ -1292,6 +1292,22 @@ function routeRequest (req, res, routes) {
req.urlParameters = {};
}
if (req.path) {
var path = req.path;
req.path = function (params, suffix) {
var p = path;
params = params || req.urlParameters;
Object.keys(params).forEach(function (key) {
p = p.replace(new RegExp(':' + key, 'g'), params[key]);
});
suffix = suffix || req.suffix;
if (Array.isArray(suffix)) {
suffix = suffix.join('/');
}
return p.replace(/\*$/, suffix || '');
};
}
var func = action.route.callback.controller;
if (func === null || typeof func !== 'function') {