-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subrouters and middlewares #41
Comments
I've made a PR: #42 |
this makes total sense to me ...why should middleware of group1 run on a group2 route? |
@arunoda is the project still active ? |
If someone else faces the same issue, the reason for it lies in the code. In the example given, you would expect const group1 = Picker.filter(req => req.method === 'POST');
group1.middleware(fakeMiddelware(2));
const group2 = Picker.filter(req => req.method === 'POST');
group2.middleware(fakeMiddelware(4)); you will end up with the same problem because the One solution I found is to filter by the route of the filtered group stored in import _ from 'lodash';
const mailboxRoutes = Picker.filter(function(req) {
return req.method === 'POST' && _.some(this.routes, routeRegEx => routeRegEx.test(req.url));
}); |
For anyone interested in route-specific middleware and not wanting to bother with filters, I've figure that out and added a wiki page for it: https://github.com/meteorhacks/picker/wiki/Example-of-route-specific-middleware |
It's not clear what is the excepted behavior with middleware at the subrouter level. At the moment, this happens:
Would it not make more sense for the middlewares to be applied only if the route matches, and for a subrouter to apply its parent router's middlewares first and then the subrouter level middlewares?
The text was updated successfully, but these errors were encountered: