var geoip = require('geoip-ultralight');
// Unlike geoip-lite's lookup() call, geoip-ultralight exposes
// a lookupCountry() function to avoid confusion
var ip = "207.97.227.239";
geoip.lookupCountry(ip); // => "US"
You'll probably be running behind some kind of frontend proxy, so the host header on incoming requests will be useless, as it'll be the IP of the proxy rather than the client.
The X-Forwarded-For header is your friend. Have nginx add them for you with:
Use https://www.npmjs.com/package/geoip-ultralight
You'll probably be running behind some kind of frontend proxy, so the host header on incoming requests will be useless, as it'll be the IP of the proxy rather than the client.
The
X-Forwarded-For
header is your friend. Have nginx add them for you with:And then you can pull the client ip from there or have express/keystone do it for you by setting:
See: