I'd like to apply a filter on certain methods. I have an authorization filter which I'd like to only work on GET and POST methods. The solution is not to add that check within the authorization method itself, but I feel that is much uglier.
How it has to be now:
Future<bool> filterAuth(HttpRequest r) {...}
...
var router = new Router(server)
..filter(new RegExp(r'/auth/.*'), (HttpRequest r) {
if (r.method != 'OPTIONS') {
return filterAuth(r);
}
return new Future.value(true);
})
...
The cleaner solution:
var router = new Router(server)
..filter(new RegExp(r'/auth/.*'), methods: ['GET', 'POST'], filterAuth);
I'd like to apply a filter on certain methods. I have an authorization filter which I'd like to only work on GET and POST methods. The solution is not to add that check within the authorization method itself, but I feel that is much uglier.
How it has to be now:
The cleaner solution: