| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Creates middleware for logging access and new connections |
| 31 | + * @param {boolean} listen If listen mode is enabled via config or command line |
| 31 | 32 | * @returns {import('express').RequestHandler} |
| 32 | 33 | */ |
| 33 | 34 | export default function accessLoggerMiddleware(listen) { |
| 34 | 35 | return function (req, res, next) { |
| 35 | 36 | const clientIp = getRealIpFromHeader(req); |
| 36 | 37 | const userAgent = req.headers['user-agent']; |
| 37 | 38 | |
| 38 | 39 | if (listen && !knownIPs.has(clientIp)) { |
| 39 | 40 | // Log new connection |
| 40 | 41 | console.info(color.yellow(`New connection from ${clientIp}; User Agent: ${userAgent}\n`)); |
| 41 | 42 | knownIPs.add(clientIp); |