koajs / joi-router

Configurable, input and output validated routing for koa
MIT License
450 stars 96 forks source link

Access current route definition #15

Closed kbrandwijk closed 8 years ago

kbrandwijk commented 8 years ago

I would like to use my own middleware on the routes. I know how to define it from the documentation, and the middleware is hit, but I would like to access the current route definition in it. Similar to how joi-router adds the validate property to the route definition, I would like to add my own (roles). How can I access the current route definition from my middleware?

aheckmann commented 8 years ago

The route definition ({ method: .., path: .., validate:.. etc}) is not currently exposed to the middleware/handler but seems like a good idea. Ideally we add this to ctx.state.route.

Care to open a PR? We should also clone the passed in definition so any middleware modifications to the definition at runtime don't cause weird side effects.

kbrandwijk commented 8 years ago

I can probably whip up a PR for it, although I'm not really sure how the cloning part fits in. Do we want the original definition exposed on the ctx, or do we want the actual runtime, possibly modified, one?

kbrandwijk commented 8 years ago

16

aheckmann commented 8 years ago

released in 3.1.0