diff --git a/Documentation/RefManual/Actions.md b/Documentation/RefManual/Actions.md index 9ce26e7640..87aa57af46 100644 --- a/Documentation/RefManual/Actions.md +++ b/Documentation/RefManual/Actions.md @@ -813,6 +813,15 @@ should win in this case: ] }); +If you call `next()`, the next specific routing will be used for the +original URL. Even if you modify the URL in the request object `req`, +this will not cause the `next()` to jump to the routing defined for +this next URL. If proceeds occurding the origin URL. However, if you +use `next(true)`, the routing will stop and request handling is +started with the new URL. You must ensure that `next(true)` is never +called without modifying the URL in the request object +`req`. Otherwise an endless loop will occur. + Application Deployment{#UserManualActionsApplicationDeployment} =============================================================== diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index da93592573..e39c687bb7 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -961,9 +961,15 @@ function routeRequest (req, res) { } }; - next = function () { + next = function (restart) { action = exports.nextRouting(action); - execute(); + + if (restart) { + routeRequest(req, res); + } + else { + execute(); + } }; execute(); @@ -1969,6 +1975,31 @@ function redirectRequest (req, res, options, next) { } } +//////////////////////////////////////////////////////////////////////////////// +/// @brief rewrites a request +//////////////////////////////////////////////////////////////////////////////// + +function rewriteRequest (req, res, options, next) { + 'use strict'; + + var i = 0; + var suffix = options.destination.split("/"); + + for (i = 0; i < suffix.length; ++i) { + if (suffix[i] !== "") { + break; + } + } + + if (0 < i) { + suffix = suffix.splice(i); + } + + req.suffix = suffix; + + next(true); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief redirects a request //////////////////////////////////////////////////////////////////////////////// @@ -2093,6 +2124,7 @@ exports.easyPostCallback = easyPostCallback; exports.echoRequest = echoRequest; exports.logRequest = logRequest; exports.redirectRequest = redirectRequest; +exports.rewriteRequest = rewriteRequest; exports.pathHandler = pathHandler; // some useful constants