如何在Firebase云功能中获取客户端IP地址?
问题描述:
当使用Firebase云功能将数据保存到Firebase数据库时,我还要写请求来自的IP地址.
When saving data to Firebase database with a Firebase cloud function, I'd like to also write the IP address where the request comes from.
但是,req.connection.remoteAddress
始终返回::ffff:0.0.0.0
.有没有办法获取发出请求的客户端的实际IP地址?
However, req.connection.remoteAddress
always returns ::ffff:0.0.0.0
. Is there a way to get the actual IP address of the client that makes the request?
答
如果您正在通过Firebase托管寻找客户端ip,则应使用标头fastly-client-ip
,这将是真实的客户端ip.
If you are looking for the client ip thru firebase hosting you should use the header fastly-client-ip
there will be the real client ip.