From de97cfa5fb8dfd17835c6dbcd5a5a03db69d82c8 Mon Sep 17 00:00:00 2001 From: Alan Plum Date: Thu, 7 May 2015 01:19:03 +0200 Subject: [PATCH] Converted req.path into a method (no longer useless). --- js/server/modules/org/arangodb/actions.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index 9fd736fa78..e26890293a 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -970,7 +970,7 @@ function flattenRouting (routes, path, rexpr, urlParameters, depth, prefix) { result = result.concat(flattenRouting( parameter.match, - path + "/", + 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') {