mirror of https://gitee.com/bigwinds/arangodb
added around
This commit is contained in:
parent
a2024c5b49
commit
e7e9afd4a7
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue