execute method

Future<MiddlewareContext> execute(
  1. Object? request,
  2. String path
)

Implementation

Future<MiddlewareContext> execute(Object? request, String path) async {
  // Execute global middleware
  final context = await _globalChain.execute(request);

  if (!context.shouldContinue) return context;

  // Execute route-specific middleware
  for (final route in _routeMiddleware) {
    if (route.matches(path)) {
      for (final middleware in route.middleware) {
        if (!context.shouldContinue) break;
        await middleware(request, context);
      }
    }
  }

  return context;
}