使用Modulus从Meteor访问客户端的IP地址(不是负载均衡器的IP地址)



我在modulus.io上托管了一个https Meteor网络应用程序。根据这里的建议,我有一个服务器方法:

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

我在我的浏览器控制台上调用实时网站:

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

但这总是返回Modulus的负载均衡器的IP地址54.236.216.66。

如何访问客户端的IP地址而不是负载平衡器的IP地址?

谢谢!

通过一些实验,我找到了一个解决方案:

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

最新更新