Hey guys,
For our current project, we’re in the need of the client’s IP for checking his or her location.
For this, we use this.connection.clientAddress
in a method call, but sometimes this.connection.clientAddress
will return the server’s IP, which will always return Amsterdam, where are servers are located.
We’re currently using the meteorhacks:cluster
package for load balancing, so maybe this is what’s causing the problems?
If so, how can we solve this?
But any idea why, for some users, it IS working correctly?
Not all IP address we’re logging are our servers, more like 50/50…
Hm, not really. I am no expert but is there a possibility of a dynamic number of proxies in front of a server?
Well, we’ve found a snippet that should deal with a variable amount of fowarders.
`‘tournamentCheckin.getConnectionIP’: function () {
// No need to make others wait
this.unblock();
// Locals
var conn = this.connection;
var ipPublic = conn.clientAddress;
var ipSource = conn.httpHeaders['x-forwarded-for'].split(',')[0]
|| ipPublic;
var prox = (process.env.HTTP_FORWARDED_COUNT)
? parseInt(process.env.HTTP_FORWARDED_COUNT)
: 0;
// Determine IP to log
return (prox) ? ipSource : ipPublic;
},`
This should work right?
But again, randomly, some IP’s are still server IP’s…
Just out of curiosity: what is that for an app? Just asking because of the tournamentCheckin
It’s BeSports, a platform where Belgian gamers can compete in online tournaments
@neglexis did you manage to solve this? We are encountering a similar issue where 50% of our users display a private IP address instead of a public one.