From f49483ad030c96fa45f149707aeb69e8009a96fa Mon Sep 17 00:00:00 2001 From: thosakwe Date: Thu, 23 Jun 2016 15:09:49 -0400 Subject: [PATCH] Global service middleware + tests --- lib/src/http/service.dart | 6 ++++++ test/routing.dart | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/src/http/service.dart b/lib/src/http/service.dart index 72340bdc..cdee9f21 100644 --- a/lib/src/http/service.dart +++ b/lib/src/http/service.dart @@ -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])); diff --git a/test/routing.dart b/test/routing.dart index e5c004b7..cdcd3caf 100644 --- a/test/routing.dart +++ b/test/routing.dart @@ -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; }