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.
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?
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.EDIT: This seems to be outdated. See the other answer.
The IP address seems to be available in
req.headers["x-forwarded-for"]
. I didn't find official information on this in the documentation, though.Also please note that if the client itself sends e.g.
X-Forwarded-For: 1.2.3.4
, the values are concatenated: