nest-morgan icon indicating copy to clipboard operation
nest-morgan copied to clipboard

Using interceptor for logging is not a good idea. Middlewares FTW

Open constb opened this issue 5 years ago • 0 comments

Request lifecycle in Nest 6.x puts interceptors after guards. That means if some AuthGuard denies request, it won't be logged. Nest middlewares are the very first thing to execute and, conveniently, happen to be express-compatible (even when fastify adapter is used). That makes putting vanilla morgan in app.use() before app.listen() in main.ts the only way to correctly log all requests.

constb avatar Oct 24 '19 04:10 constb