redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Is there a way to use a middleware just for some specific endpoints? #134

Closed Pacane closed 8 years ago

Pacane commented 9 years ago

Seems like when I do

  app.addShelfMiddleware(someMiddleWare());
  app.start();

It is used for all the endpoints. I figured I could wrap my middleWare and check for the request.url to see if it matches XYZ endpoints, but I was wondering if there is/should be a way of doing this with redstone/shelf.

I can see in shelf that there's support for route-specific middleware with

myRouter.get('/', (_) => new Response.ok("Hello World"), middleware: logRequests());
Pacane commented 9 years ago

I guess I could also use the strategy in this post http://redstonedart.org/2014/07/18/authentication-and-authorization/

and make a redstone plugin for it (and annotate my groups/specific endpoints with it)

cgarciae commented 9 years ago

@Pacane I think Redstone plugins are just shelf middleware under the hood. I've created a couple of documented and undocumented plugins for Redstone, what do you need?

Pacane commented 9 years ago

I was looking to use shelf_auth package but it was using all the endpoints as its scope.

What I need specifically, is to protect my end points with a session mechanism that's based on a token (jwt)

Pacane commented 8 years ago

Plugins seem to be the thing I was looking for. Thanks!