Global service middleware + tests
This commit is contained in:
parent
897a09d359
commit
f49483ad03
2 changed files with 8 additions and 1 deletions
|
@ -60,6 +60,12 @@ class Service extends Routable {
|
|||
Service() : super() {
|
||||
Map restProvider = {'provider': Providers.REST};
|
||||
|
||||
// Add global middleware if declared on the instance itself
|
||||
Middleware before = _getAnnotation(this, Middleware);
|
||||
if (before != null) {
|
||||
routes.add(new Route("*", "*", before.handlers));
|
||||
}
|
||||
|
||||
Middleware indexMiddleware = _getAnnotation(this.index, Middleware);
|
||||
get('/', (req, res) async {
|
||||
return await this.index(mergeMap([req.query, restProvider]));
|
||||
|
|
|
@ -9,9 +9,10 @@ testMiddlewareMetadata(RequestContext req, ResponseContext res) async {
|
|||
return "This should not be shown.";
|
||||
}
|
||||
|
||||
@Middleware(const ['intercept_service'])
|
||||
class QueryService extends Service {
|
||||
@override
|
||||
@Middleware(const ['intercept_service', 'interceptor'])
|
||||
@Middleware(const ['interceptor'])
|
||||
read(id, [Map params]) {
|
||||
return params;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue