Skip to content

Instantly share code, notes, and snippets.

@kleinron
Created May 18, 2015 21:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kleinron/5f66b08cc125c05e6eff to your computer and use it in GitHub Desktop.
Save kleinron/5f66b08cc125c05e6eff to your computer and use it in GitHub Desktop.
When using Morgan as the access log writer, in a Vanilla server, use this snippet to respect the x-forwarded-for header as the original client's ip address.
morgan.token('remote-addr', function (req, res) {
var ffHeaderValue = req.headers['x-forwarded-for'];
return ffHeaderValue || req.connection.remoteAddress;
});
@velopert
Copy link

Thanks!

@jtktam
Copy link

jtktam commented Jun 30, 2020

thank you for this tip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment