Dart shelf server: only apply middleware to selected routes

36 Views Asked by At

In Dart shelf_router, I can add middleware like so:

final handler = Pipeline()
    .addMiddleware(logRequests())
    .addMiddleware(auth())
    .addHandler(router.call);

However, I want the auth middleware to only apply to certain routes, not all of them:

final router = Router()
  ..get('/public', _publicHandler)    // no auth
  ..get('/private', _privateHandler); // this route should apply auth

How would I do that?

0

There are 0 best solutions below