Feature Request: Middleware decorator on Server
thekevinbrown opened this issue · 3 comments
thekevinbrown commented
Is it possible to declare once that you want the middleware to apply to every route you make on a server, not just a controller?
If it is possible, could you let me know what I missed, and if not, consider this a feature request that I may very well be able to make a PR for, just wanted to check in first.
joeykilpatrick commented
Hello,
This is possible with normal express before adding controllers. See gist here.
seanpmaxwell commented
I you want a middleware to apply to every route on all controllers, just add it to the root parent controller.
@Controller('parent')
@ClassMiddleware( ... ) <--- Put you're middleware here
@ChildControllers([
new ChildA1Controller(),
new ChildA2Controller(),
new ChildB1Controller(),
])
export class ParentController {
@Get()
private get(req: Request, res: Response) {
const message = 'Hi I\'m the parent controller';
Logger.Info(message);
return res.status(OK).json({message});
}
}
thekevinbrown commented
@seanpmaxwell i don’t have a root controller in this app though, that’s why I want it to apply to the server.