如何在 Meteorjs 上检索 IP 地址?

How to Retrieve IP address on Meteorjs?

如何在 Meteorjs 上检索 IP 地址?。有什么包裹吗?请指教

安装 http 包:

meteor add http

然后使用它:

var result = HTTP.get("https://api.ipify.org");

console.log(result.content)

您可以使用mizzao:user-status 包获取用户的IP 地址。它是用于获取有关客户端用户连接和状态的此类信息的标准包。

安装:meteor add mizzao:user-status

然后您可以使用 UserStatus.connections(内存中)集合获取服务器上所有连接的信息,在以下字段中:

  • userId:用户标识,如果连接已通过身份验证。
  • ipAddr: 连接的远程地址。从不同地方登录的用户每个连接将有一个文档。 (这​​是你需要的字段)

一件事,来自他们在 Atmosphere 网站上的 documentation

Note that to read client IP addresses properly, you must set the HTTP_FORWARDED_COUNT environment variable for your app, and make sure that IP address headers are forwarded for any reverse proxy installed in front of the app. See the Meteor docs on this for more details.