相关疑难解决方法(0)

如何在 us-central1 以外的区域使用 httpsCallable for web

我部署了一个云函数,如下所示:

export const publishVersion = functions
  .region("europe-west2")
  .https.onCall(async (data, context) => {}
Run Code Online (Sandbox Code Playgroud)

然后在我的 Web 客户端中,我定义了一个函数来调用它:

import { functions } from "firebase";

const callPublishVersion = functions().httpsCallable("publishVersion");

export function publishVersion(
  guidelineId: string,
  guidelineReference: string
) {
  return callPublishVersion({
    id: guidelineId,
    reference: guidelineReference
  });
}
Run Code Online (Sandbox Code Playgroud)

请注意,我包装函数的唯一原因是在我的客户端中进行严格的输入,但这不是这个问题的重点。

问题是,如果我在本地服务器 (localhost) 上运行 Web 客户端并调用该函数,则有两件事似乎会出错。我收到 CORS 错误:

从源“ http://localhost:3000 ”获取“ https://us-central1-my-project.cloudfunctions.net/publishVersion ”的访问权限已被 CORS 政策阻止:对预检请求的响应未通过访问控制检查:预检请求不允许重定向。

而且,us-central1即使我的功能已部署到europe-west2. 当我部署 firebase-tools 时会告诉我 url 应该是什么:

? 函数[publishVersion(europe-west2)]:创建操作成功。函数 URL(发布版本):https ://europe-west2-baymard-gemini-dev.cloudfunctions.net/publishVersion

我在哪里/如何控制事物以防止出现此 CORS 错误,以及如何将 httpsCallable 定向到其他区域?

官方文件没有提到任何这一点。 …

firebase google-cloud-functions

5
推荐指数
2
解决办法
1637
查看次数

标签 统计

firebase ×1

google-cloud-functions ×1