英文:
CORS issue with onCall HTTPS firebase function
问题
I get this error message: Access to fetch at 'https://us-central1-myapp.cloudfunctions.net/myFunction' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
The function looks like this:
exports.myFunction = functions.region("europe-central2").https.onCall((data, context) => {});
There should be a better way than adding members/principals through Google Cloud console.
EDIT: I'm also using the firebase functions framework to call the function.
英文:
I get this error message: Access to fetch at 'https://us-central1-myapp.cloudfunctions.net/myFunction' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
The function looks like this:
exports.myFunction = functions.region("europe-central2").https.onCall((data, context) => {});
There should be a better way than adding members/principals through Google Cloud console.
EDIT: I'm also using the firebase functions framework to call the function.
答案1
得分: 1
我使用的解决方案是来自这里的第一个建议。
在客户端中,您需要指定函数托管在哪个区域。如果您使用默认的 "us-central1" 服务器,我认为这是不必要的。但在我的情况下,我需要添加 "europe-central2"。
import { getFunctions } from "firebase/functions";
export const fbFunctions = getFunctions(app, "europe-central2");
英文:
The solution I used was the first suggestion from here.
You need to specify in which region the function is hosted in the client. I don't believe it's necessary if you have the default "us-central1" server. But in my case I needed to add "europe-central2"
import { getFunctions } from "firebase/functions";
export const fbFunctions = getFunctions(app, "europe-central2");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论