在什么条件下req.connection.remoteAddress可以为空(ExpressJS) [英] Under What Conditions can req.connection.remoteAddress be Blank (ExpressJS)

查看:434
本文介绍了在什么条件下req.connection.remoteAddress可以为空(ExpressJS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Node.js v6.9.4下的快速应用程序,可以通过HTTP和HTTPS进行服务.

I have an express app running under Node.js v6.9.4, serving both via HTTP and HTTPS.

我注意到几次传入的请求都有空白的remoteAddress数据.

I've noticed a few times that requests coming in have had blank remoteAddress data.

在什么条件下请求可以没有/空白的remoteAddress?

Under what conditions can a request have no / blank remoteAddress?

推荐答案

在代理后面的远程地址为空

remote address is blank when behind a proxy

https://github.com/hapijs/hapi/issues/1210

您可以使用

const ip = req.headers['x-forwarded-for'] || (req.connection && req.connection.remoteAddress) || ''

这篇关于在什么条件下req.connection.remoteAddress可以为空(ExpressJS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆