Yes, you can limit the execution of middleware to specific controllers or routes in Deepkit HTTP.
To apply middleware to specific controllers or routes, you can use the httpMiddleware.for(T).forControllers()
or httpMiddleware.for(T).forRoutes()
methods, where T
is the middleware class or function.
For example, to apply a middleware to specific controllers, you can use the forControllers()
method:
import { httpMiddleware } from '@deepkit/http'; // ... new App({ // ... middlewares: [ httpMiddleware.for(MyMiddleware).forControllers(MyController1, MyController2), ], // ... }).run();
Alternatively, you can apply middleware to specific routes using the forRoutes()
method:
import { httpMiddleware } from '@deepkit/http'; // ... new App({ // ... middlewares: [ httpMiddleware.for(MyMiddleware).forRoutes({ path: '/route1', httpMethod: 'GET', }), ], // ... }).run();