You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase onCall函数遭CORS拦截,多种配置尝试均无效

Firebase onCall函数部署后CORS拦截问题求助

本地运行Firebase onCall函数完全正常,但部署到预发布环境后就触发CORS拦截,试遍所有可行方案都没解决。

已尝试的CORS配置选项包括:

  • { cors: false }
  • { cors: true }
  • { cors: ["/https://example\.appspot.com/"] }
  • { cors: ["https://example.appspot.com"] }

函数代码示例:

const { onCall, HttpsError } = require('firebase-functions/v2/https');
const { initializeApp, cert } = require('firebase-admin/app');
const { getFirestore, FieldValue } = require('firebase-admin/firestore');
const { getAuth } = require('firebase-admin/auth');

initializeApp();
...

exports.currentSSOPartners = onCall(
    { cors: false },
    async (request) => {

无论用哪种配置,都会抛出以下错误:

Access to fetch at 'https://us-central1-example.cloudfunctions.net/currentSSOPartners' from origin 'https://example.appspot.com' has been blocked by CORS policy:

除此之外,还尝试过添加调用者权限的方案,翻遍GitHub上6页关于onCall函数CORS配置的讨论并测试所有给出的方法,结果还是被CORS拦截,实在找不到解决办法,特此求助。

内容的提问来源于stack exchange,提问作者lando2319

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 12:22:34