Access client's IP address (not the load balancer's) from Meteor, with Modulus

259 views Asked by At

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!

1

There are 1 answers

1
Racing Tadpole On BEST ANSWER

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;
      }
   }
});