BugFixes bzgl. Observables, Logging Anpassungen, Endpunkt hardening, dotenv-flow usage
This commit is contained in:
@@ -7,19 +7,21 @@ export class RequestDurationMiddleware implements NestMiddleware {
|
||||
|
||||
use(req: Request, res: Response, next: NextFunction) {
|
||||
const start = Date.now();
|
||||
const clientIp = req.ip;
|
||||
this.logger.log(`Entering ${req.method} ${req.originalUrl} from ${clientIp}`);
|
||||
|
||||
res.on('finish', () => {
|
||||
// const duration = Date.now() - start;
|
||||
// this.logger.log(`${req.method} ${req.url} - ${duration}ms`);
|
||||
const duration = Date.now() - start;
|
||||
let logMessage = `${req.method} ${req.url} - ${duration}ms`;
|
||||
let logMessage = `${req.method} ${req.originalUrl} - ${duration}ms - IP: ${clientIp}`;
|
||||
|
||||
if (req.method === 'POST' || req.method === 'PUT') {
|
||||
const body = JSON.stringify(req.body);
|
||||
logMessage += ` - Body: ${body}`;
|
||||
logMessage += ` - Incoming Body: ${body}`;
|
||||
}
|
||||
|
||||
this.logger.log(logMessage);
|
||||
});
|
||||
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user