CORS问题与onCall HTTPS Firebase函数相关。

huangapple go评论89阅读模式
英文:

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");

huangapple
  • 本文由 发表于 2023年3月1日 08:18:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75598530.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定