Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

log the IP address as seen by Express, if available #684

Merged
merged 1 commit into from

3 participants

@natesilva

Currently, the connect.logger middleware logs the socket’s IP address.

Instead, it should prefer to log req.ip—the IP address as seen by Express. This is especially useful when the Express’ “trust proxy” option is enabled. In that case, it will log the user’s IP address, and not the proxy’s IP address.

If not using a proxy, or if req.ip is not available (for example, you’re not using Express), it will log the immediate IP address, as before.

Nate Silva log the IP address as seen by Express, if available
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.
b81f3b7
@rauchg

+1

@tj
Owner
tj commented

ideally we'd move express's stuff into an npm lib and add .logger({ trustProxy: true }) or something to make it less express specific but since this will just noop I'll merge for now

@tj tj merged commit 86a40ba into senchalabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 2, 2012
  1. log the IP address as seen by Express, if available

    Nate Silva authored
    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.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/middleware/logger.js
View
2  lib/middleware/logger.js
@@ -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));
});
/**
Something went wrong with that request. Please try again.