2

I have an https Meteor webapp hosted on modulus.io. Following the advice here I have a server method:

Meteor.methods({
    printIP: function() {
        return this.connection.clientAddress;
    }
});

I call this from my browser console on the live site:

Meteor.call('printIP', function(err, ip) { console.log(ip); })

But this always returns Modulus's load balancer's IP address, 54.236.216.66.

How can I access the client's IP address instead of the load balancer's?

Thanks!

Community
  • 1
  • 1
Racing Tadpole
  • 4,270
  • 6
  • 37
  • 56

1 Answers1

4

With some experimentation I have found a solution:

Meteor.methods({
   printIP: function() {
      if (this.connection.httpHeaders && this.connection.httpHeaders['x-forwarded-for']) {
         return this.connection.httpHeaders['x-forwarded-for'];
      } else {
         return this.connection.clientAddress;
      }
   }
});
Racing Tadpole
  • 4,270
  • 6
  • 37
  • 56
  • Note that the `X-Forwarded-For` header could be a comma-separated list (actually, a comma+space-separated list) of IP addresses, where the first address is the original client's. – MasterAM Jan 01 '16 at 11:58