Skip to content

Add methods optional argument to filter #80

@tusj

Description

@tusj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions