1
0
Fork 0

added around

This commit is contained in:
Frank Celler 2014-09-01 23:23:06 +02:00
parent a2024c5b49
commit e7e9afd4a7
2 changed files with 47 additions and 0 deletions

View File

@ -113,6 +113,10 @@ example).
<!-- js/server/modules/org/arangodb/foxx/controller.js -->
@startDocuBlock JSF_foxx_controller_after
!SUBSECTION Around
<!-- js/server/modules/org/arangodb/foxx/controller.js -->
@startDocuBlock JSF_foxx_controller_around
!SECTION The Request and Response Objects

View File

@ -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