From e7e9afd4a73a8bfb7520a1c3f09eb3072c94fc2c Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Mon, 1 Sep 2014 23:23:06 +0200 Subject: [PATCH] added around --- .../Books/Users/Foxx/FoxxController.mdpp | 4 ++ .../modules/org/arangodb/foxx/controller.js | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Documentation/Books/Users/Foxx/FoxxController.mdpp b/Documentation/Books/Users/Foxx/FoxxController.mdpp index 33156044c9..c93361c052 100644 --- a/Documentation/Books/Users/Foxx/FoxxController.mdpp +++ b/Documentation/Books/Users/Foxx/FoxxController.mdpp @@ -113,6 +113,10 @@ example). @startDocuBlock JSF_foxx_controller_after +!SUBSECTION Around + +@startDocuBlock JSF_foxx_controller_around + !SECTION The Request and Response Objects diff --git a/js/server/modules/org/arangodb/foxx/controller.js b/js/server/modules/org/arangodb/foxx/controller.js index 4880ce64a6..63517e6f17 100644 --- a/js/server/modules/org/arangodb/foxx/controller.js +++ b/js/server/modules/org/arangodb/foxx/controller.js @@ -415,6 +415,49 @@ extend(Controller.prototype, { }); }, +//////////////////////////////////////////////////////////////////////////////// +/// @startDocuBlock JSF_foxx_controller_around +/// +/// `FoxxController#around(path, callback)` +/// +/// The around function takes a *path* on which it should watch and a function +/// that it should execute around the function which normally handles the +/// route. If you do omit the path, the function will be executed before each +/// request, no matter the path. Your function gets a Request and a Response +/// object and a next funcion, which you must call to execute the handler for +/// that route. +/// +/// @EXAMPLES +/// +/// ```js +/// app.around('/high/way', function(req, res, opts, next) { +/// //Do some crazy request logging +/// next(); +/// //Do some more crazy request logging +/// }); +/// ``` +/// @endDocuBlock +//////////////////////////////////////////////////////////////////////////////// + + around: function (path, func) { + 'use strict'; + + if (is.notExisty(func)) { + func = path; + path = "/*"; + } + + this.routingInfo.middleware.push({ + priority: this.currentPriority = this.currentPriority + 1, + url: {match: path}, + action: { + callback: function (req, res, opts, next) { + func(req, res, opts, next); + } + } + }); + }, + //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_controller_getUsers /// @brief Get the users of this controller