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

标签 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);
        ....
    }
});

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

最佳答案

查看用户状态包。 https://github.com/mizzao/meteor-user-status

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

关于Meteor - 如何在 Helper 中获取当前访问者的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28511314/

相关文章:

twitter-bootstrap - meteor 编译自定义 Bootstrap 少的例子?

javascript - 如何在 Fiber 中运行 Meteor insert

email - 如何为 Meteor 电子邮件 sendMail 配置 SSL?

javascript - 如何从助手返回 html 元素?

javascript - Meteor.settings 对象何时何地初始化?

meteor - 如果模板在 DOM 中重新定位,Meteor 模板事件是否会丢失?

meteor - 有没有办法告诉 meteor 一个集合是静态的(永远不会改变)?

meteor - 如何删除或删除 session 变量?

Meteor如何在mongo中保存模板

meteor 动态表单生成