express-pino-logger icon indicating copy to clipboard operation
express-pino-logger copied to clipboard

how to log cdn cloudflare ip address?

Open epubreader opened this issue 3 years ago • 2 comments

req.remoteAddress does not working, how to change to req.header('x-real-ip'), mywebsite is running behind cloudflare cdn.

        serializers: {
            req: function requestSerializer(req) {
                return {
                    id: req.id,
                    method: req.method,
                    url: req.url,
                    remoteAddress: req.header('x-real-ip') || req.connection.remoteAddress,
                    remotePort: req.remotePort,
                    body: req.raw.body,
                };
            },
        },

epubreader avatar Feb 20 '21 12:02 epubreader

isn't the snippet you pasted enough?

mcollina avatar Feb 20 '21 13:02 mcollina

I believe CloudFlare forwards the connecting clients IP via the CF-Connecting-IP header rather than the X-Real-IP header.

James11T avatar May 04 '22 20:05 James11T