Skip to content

Commit

Permalink
log the IP address as seen by Express, if available
Browse files Browse the repository at this point in the history
For `remote-addr`, the logging middleware should use `req.ip`, the IP
address seen by Express. This is especially useful when behind a proxy
with the Express “trust proxy” option. If `req.ip` is not enabled,
fallback to the traditional method.
  • Loading branch information
Nate Silva committed Nov 2, 2012
1 parent 6c41308 commit b81f3b7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/middleware/logger.js
Expand Up @@ -299,7 +299,7 @@ exports.token('referrer', function(req){
*/

exports.token('remote-addr', function(req){
return req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress));
return req.ip || req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress));
});

/**
Expand Down

0 comments on commit b81f3b7

Please sign in to comment.