我正在尝试从我的反应性客户端调用我的Firebase云功能。
httpsCallable()
(如描述的这里)从客户端直接调用云函数。与调用HTTP请求相比,此方法似乎有几个优点。但是,使用这种方法,我将得到以下CORS错误:CORS策略阻止了从源'https://us-central1-myapp.cloudfunctions.net/helloWorld‘获取'http://localhost:3000’的访问
我该怎么做呢?值得这么麻烦吗?这真的是首选的方法吗?
这是我的云功能:
import * as functions from 'firebase-functions';
export const helloWorld = functions.https.onRequest((request, response) => {
response.send('Hello from Firebase!');
});
我是这样从我的客户那里打电话的:
const sayHello = async (): Promise<string> => {
const helloWorld = firebase.functions().httpsCallable('helloWorld');
const result = await helloWorld();
return result.data;
};
发布于 2019-10-06 10:52:19
通过做
const helloWorld = firebase.functions().httpsCallable('helloWorld');
const result = await helloWorld();
您确实是在通过定义被调用的函数来调用可调用云函数,但是,如下所示
functions.https.onRequest((request, response) => {})
您正在定义一个HTTPS云函数 ,它是不同的。
您应该将云函数定义为可调用函数,如下所示:
export const helloWorld = = functions.https.onCall((data, context) => {
return { response: 'Hello from Firebase!' };
});
https://stackoverflow.com/questions/58254449
复制相似问题