only static method

Middleware only(
  1. String path,
  2. Middleware middleware
)

Wraps a middleware to ONLY execute if the request path matches path.

Implementation

static Middleware only(String path, Middleware middleware) {
  return (ctx, next) async {
    if (ctx.request.uri.path == path) {
      return middleware(ctx, next);
    }
    return next();
  };
}