本地调用Firebase云函数
我知道这个问题已经被问了很多次,我已经阅读了所有的答案,但仍然没有一个有效的解决方案 我尝试使用本地调用Firebase云函数,firebase,google-cloud-functions,aws-cloud9,Firebase,Google Cloud Functions,Aws Cloud9,我知道这个问题已经被问了很多次,我已经阅读了所有的答案,但仍然没有一个有效的解决方案 我尝试使用firebase-serve或firebase-emulators:start和运行我的firebase函数并在本地托管 这让我有点像: ✔ functions: Using node@8 from host. ✔ functions: Emulator started at http://127.0.0.1:8081 i functions: Watching "/home/ec2-user/
firebase-serve
或firebase-emulators:start
和运行我的firebase函数并在本地托管
这让我有点像:
✔ functions: Using node@8 from host.
✔ functions: Emulator started at http://127.0.0.1:8081
i functions: Watching "/home/ec2-user/environment/functions" for Cloud Functions...
i hosting: Serving hosting files from: build
✔ hosting: Local server: http://127.0.0.1:8080
⚠ functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to XXXXX-d5435114eb69.json. Non-emulated services will access production using these credentials. Be careful!
✔ functions[log]: http function initialized (http://127.0.0.1:8081/XXXXX/us-central1/log).
托管服务器工作正常,有一个log
cloud函数在http://127.0.0.1:8081/XXXXX/us-central1/log
。但是跑步:
const log = firebase.functions().httpsCallable('log');
log("Hello World");
从本地托管站点尝试调用已部署的云函数,并给出一个CORS错误:
CORS策略已阻止从源“”获取“”的访问
我正在使用加载sdk
是否可以在本地运行托管和功能以进行开发 我也有同样的问题,我的解决方案很简单,我使用了
https.onRequest
而不是https.onCall
:
不工作:
//云函数
exports.testFunction=functions.https.onRequest((请求,响应)=>{
回复。发送(“来自Firebase的你好!”);
})
工作:
//云函数
exports.testFunction=functions.https.onCall(()=>{
返回{消息:“来自Firebase的你好!”}
})
也许这也是你的问题?我也有同样的问题,我的解决方案很简单,我使用了
https.onRequest
而不是https.onCall
:
不工作:
//云函数
exports.testFunction=functions.https.onRequest((请求,响应)=>{
回复。发送(“来自Firebase的你好!”);
})
工作:
//云函数
exports.testFunction=functions.https.onCall(()=>{
返回{消息:“来自Firebase的你好!”}
})
也许这也是你的问题?那就行了。但是它改变了你从客户端调用函数的方式,这是可行的。但它改变了从客户端调用函数的方式。