【发布时间】:2021-08-10 19:38:58
【问题描述】:
我已经使用 functions 和 hosting 功能初始化了一个模板化 Firebase 项目。
我取消了模板化 HTTP 函数的注释:
export const helloWorld = functions.https.onRequest((req, res) => {
functions.logger.info("Hello logs!", {structuredData: true});
res.send("Hello from Firebase!");
});
并且还在模板化的public/index.html文件中添加了以下代码:
const functions = firebase.functions();
const helloWorld = functions.httpsCallable('helloWorld');
helloWorld().then((res) => { console.log(res); });
我已经尝试过使用多种配置来完成这项工作:
- 用于托管的 Firebase 模拟器,调用已部署的 Firebase 功能。
- 用于托管的 Firebase 模拟器,调用模拟函数(Firebase 函数模拟器)。
- 已部署的主机,调用已部署的 Firebase 函数。
所有配置都会产生以下结果:
Access to fetch at 'https://us-central1-my-project.cloudfunctions.net/helloWorld' from origin 'http://127.0.0.1:5000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我没有更改模板化、自动生成的 Firebase 代码中的任何内容,但没有我所说的内容。
我错过了什么?
【问题讨论】:
标签: javascript node.js firebase google-cloud-functions cors