我很难找到如何从路由访问REST客户端的IP地址.
server.get('api/foo', function(req, res, next) {
// How can I access the IP address of the requester from here?
}
Run Code Online (Sandbox Code Playgroud)
Kur*_*ler 16
其他答案在代理后面不起作用,在这些情况下你会获得代理服务器地址.
req.headers['x-forwarded-for'] || req.connection.remoteAddress;
Run Code Online (Sandbox Code Playgroud)
如果代理在x-forwarded-for头文件中设置原始IP,默认情况下可以添加到nginx之类的内容,则可以在代理后面工作.
| 归档时间: |
|
| 查看次数: |
7092 次 |
| 最近记录: |