requestLogger.ts
Ricky/StrongPassword/backend/src/middleware/requestLogger.ts
import { Request, Response, NextFunction } from 'express';
import logger from '../utils/logger';
export const requestLogger = (req: Request, res: Response, next: NextFunction) => {
const start = Date.now();
// Log the incoming request
logger.request(req.method, req.url, req.ip);
// Override res.end to log the response
const originalEnd = res.end;
res.end = function(chunk?: any, encoding?: any) {
const responseTime = Date.now() - start;
logger.response(req.method, req.url, res.statusCode, responseTime);
return originalEnd.call(this, chunk, encoding);
};
next();
};
Related articles
__init__.py
__init__.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/__init__.py).
Read article →auth.py
auth.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/auth.py).
Read article →routes.py
routes.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/admin/routes.py).
Read article →config.py
config.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/config.py).
Read article →admin_ingest.py
admin_ingest.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_ingest.py).
Read article →admin_stats.py
admin_stats.py — python source code from the Ricky learning materials (Ricky/Cat Project Final/back_web-4/app/routes/admin_stats.py).
Read article →