Search code examples
javameteorddp

How to get the source ip address of DDP call by a Java client in Meteor


I call a meteor server function from a java client via ddp, how to get the ip of the java server in meteor in order to restrict the access ?


Solution

  • Inside a Meteor method, you could access client information through this.connection object. The detail of this object is specified here. To get IP of client you could do:

    Meteor.methods({
      test() {
        const ip = this.connection.clientAddress;
      }
    });
    

    Note that if your server is run behind proxies, you will need to set the HTTP_FORWARDED_COUNT environment variable to the number of proxies in front of your server.