[英]Meteor - How to get IP address of current visitor in Helper
I tried using this approach but I get undefined as the value for the variable named clientIpAddress. 我尝试使用这种方法,但未获得名为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);
....
}
});
If some one could assist me with this, it will be greatly appreciated. 如果有人可以帮助我,将不胜感激。
Check out the user-status
package. 签出
user-status
包。 https://github.com/mizzao/meteor-user-status https://github.com/mizzao/meteor-user-status
This gives you Meteor.user().status.lastLogin.ipAddr
which you can then use in a helper (first make sure the field is published). 这将为您提供
Meteor.user().status.lastLogin.ipAddr
,然后您可以在帮助器中使用它(首先确保该字段已发布)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.