Meteor - 如何在Helper中获取当前访客的IP地址

时间:2015-02-14 01:10:51

标签: meteor

我尝试使用这种方法,但我将未定义为名为clientIpAddress的变量的值。

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

Template.home.helpers({
    starsAlreadyReceivedFromIpAddress: function () {
        var clientIpAddress;
        Meteor.call("getClientIpAddress", function(err, ipAddress) {
           clientIpAddress = ipAddress;
        });
        console.log(clientIpAddress);
        ....
    }
});

如果有人可以帮助我,我们将不胜感激。

1 个答案:

答案 0 :(得分:3)

查看user-status包。 https://github.com/mizzao/meteor-user-status

这将为您提供Meteor.user().status.lastLogin.ipAddr,然后您可以在帮助器中使用它(首先确保该字段已发布)。