| // Request logging middleware - tracks all API calls | |
| const requestLogger = (req, res, next) => { | |
| const timestamp = new Date().toISOString(); | |
| const method = req.method; | |
| const url = req.url; | |
| const ip = req.ip || req.connection.remoteAddress; | |
| console.log(`[${timestamp}] ${method} ${url} - IP: ${ip}`); | |
| // Log response time | |
| const start = Date.now(); | |
| res.on('finish', () => { | |
| const duration = Date.now() - start; | |
| console.log(`[${timestamp}] ${method} ${url} - Status: ${res.statusCode} - ${duration}ms`); | |
| }); | |
| next(); | |
| }; | |
| module.exports = requestLogger; | |