Global service middleware + tests

This commit is contained in:
thosakwe 2016-06-23 15:09:49 -04:00
parent 897a09d359
commit f49483ad03
2 changed files with 8 additions and 1 deletions

View file

@ -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]));

View file

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