Consumer for configuring middleware in modules
Provides fluent API for registering middleware with route targeting. Used by modules implementing MiddlewareConfigurable interface.
@Module({ providers: [...] })export class AppModule implements MiddlewareConfigurable { configure(consumer: MiddlewareConsumer): void { // Global logging middleware (excludes health check) consumer .apply(LoggingMiddleware) .exclude('/health') .forRoutes('*') // CORS middleware for specific controllers consumer .apply(CorsMiddleware) .forRoutes(ApiController, WebhooksController) // Rate limiting for auth endpoints consumer .apply(RateLimitMiddleware) .forRoutes({ path: '/api/v1/auth/*', method: 'post' }) }} Copy
@Module({ providers: [...] })export class AppModule implements MiddlewareConfigurable { configure(consumer: MiddlewareConsumer): void { // Global logging middleware (excludes health check) consumer .apply(LoggingMiddleware) .exclude('/health') .forRoutes('*') // CORS middleware for specific controllers consumer .apply(CorsMiddleware) .forRoutes(ApiController, WebhooksController) // Rate limiting for auth endpoints consumer .apply(RateLimitMiddleware) .forRoutes({ path: '/api/v1/auth/*', method: 'post' }) }}
Internal
Add a configuration entry (called by builder)
Start configuring middleware
Middleware classes to apply
Builder for configuring routes and exclusions
Get all configured middleware entries
Consumer for configuring middleware in modules
Provides fluent API for registering middleware with route targeting. Used by modules implementing MiddlewareConfigurable interface.
Example