[英]Meteor - How to get IP address of current visitor in Helper
我尝试使用这种方法,但未获得名为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);
....
}
});
如果有人可以帮助我,将不胜感激。
签出user-status
包。 https://github.com/mizzao/meteor-user-status
这将为您提供Meteor.user().status.lastLogin.ipAddr
,然后您可以在帮助器中使用它(首先确保该字段已发布)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.