Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Add Middleware to a set o routes #166

Closed
jonhkr opened this issue Sep 16, 2016 · 2 comments
Closed

Add Middleware to a set o routes #166

jonhkr opened this issue Sep 16, 2016 · 2 comments
Labels

Comments

@jonhkr
Copy link

jonhkr commented Sep 16, 2016

Hi,
Is it possible to add a Middleware to a set of routes without registering the middleware in every route?

@pettermahlen
Copy link
Member

You can use Stream operators, like so:

Stream<Route<?>> routes = Stream.of(route1, route2, route3)
     .map(route -> route.withMiddleware(myMiddleware));

That's a large reason we decided to go with Streams of Routes in the RoutingEngine methods; so as to avoid having to go back and forth between collections and streams when initialising applications. I have a slightly bad feeling about using streams this way (mostly because of terminal operations), but so far I'm not aware of any actual problems.

Please close if this answers your question!

@jonhkr
Copy link
Author

jonhkr commented Sep 19, 2016

Thanks @pettermahlen I'll try that.

@jonhkr jonhkr closed this as completed Sep 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants