如何从onCall
Firebase功能访问用户IP地址...
exports.MyFunction = functions.https.onCall((data, context) => {
var IPAddress; //???
console.log(IPAddress)
});
我看到也许可以用context.rawRequest.connection.remoteAddress
来获取IP地址,但是随后我看到了this post关于http
函数的信息,而且我不确定如何设置标题onCall
函数上的fastly-client-ip
。
有什么建议吗?
答案 0 :(得分:2)
请参阅:
https://firebase.google.com/docs/reference/functions/providers_https_.html#oncall https://firebase.google.com/docs/reference/functions/providers_https_.callablecontext.html https://firebase.google.com/docs/reference/functions/providers_https_.request.html#ip
exports.myCallable = functions.https.onCall((data, context) => {
return context.rawRequest.ip;
});
如果您需要路线信息:
https://firebase.google.com/docs/reference/functions/providers_https_.request.html#ips