Firebase - 预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 x-firebase-gmpid

IT技术 reactjs firebase cors firebase-storage firebase-hosting
2021-03-30 21:31:12

我的产品使用 firebase rtdb、firestore、storage、auth 和托管。我没有对我的 CORS 配置进行任何更改。但是,今天我在尝试将图像上传到存储并检索它们时开始收到以下 CORS 错误:

访问 XMLHttpRequest ' https://firebasestorage.googleapis.com/v0/b/diary-a77f6.appspot.com/o?name=images%2FJ1gU3KPfo1cTHJXhT3iopBqrvVs1%2F-M1Ah4xCQ46GvEZ2%2Palboera1%2%FBalCalifor% 201600x1200%20-%20ID%2027253.jpg ' from origin ' https://daybook.app ' 已被 CORS 政策阻止:预检中的 Access-Control-Allow-Headers 不允许请求标头字段 x-firebase-gmpid回复。

我尝试了Firebase Storage 和 Access-Control-Allow-Originhttps://cloud.google.com/storage/docs/configuring-corshttps://firebase.google.com/docs/storage/web/download- files#cors_configuration无济于事。

我的主机配置:

{
    "target": "prod",
    "public": "build/production",
    "ignore": [
        "firebase.json",
        "src/firebase/keys.js",
        "**/.*",
        "**/node_modules/**"
    ],
    "rewrites": [
        {
            "source": "**",
            "destination": "/index.html"
        }
    ],
    "headers": [
        {
            "source": "/**",
            "headers": [
                {
                    "key": "Cache-Control",
                    "value": "no-cache, no-store, must-revalidate"
                },
                {
                    "key": "Access-Control-Allow-Headers",
                    "value": "x-firebase-gmpid, Origin, Accept, Content-Type, X-Requested-With, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization"
                }
            ]
        },
        {
            "source": "**/*.@(css|js)",
            "headers": [
                {
                    "key": "Cache-Control",
                    "value": "no-cache, no-store, must-revalidate max-age=0"
                }
            ]
        },
        {
            "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
            "headers": [
                {
                    "key": "Access-Control-Allow-Origin",
                    "value": "*"
                }
            ]
        },
        {
            "source": "**/*.@(jpg|jpeg|gif|png|webp|webp|svg)",
            "headers": [
                {
                    "key": "Cache-Control",
                    "value": "max-age=7200"
                }
            ]
        }
    ]
}

这是我最近在尝试解决问题时添加的内容:

{
    "key": "Access-Control-Allow-Headers",
    "value": "x-firebase-gmpid, Origin, Accept, Content-Type, X-Requested-With, Access-Control-Request-Method,Access-Control-Request-Headers, Authorization"
}
1个回答

我认为这是 Firestore JS 客户端库的问题。我将它7.9.0从版本回滚到版本7.9.2错误消失了。

编辑:7.9.3 包含修复。

我同意,出现在 7.9.2 中。7.9.1 版也能正常工作。我在 Firebase JS SDK 存储库上创建了一个问题:github.com/firebase/firebase-js-sdk/issues/2695
2021-06-07 21:31:12
这已在最新版本 (v7.9.3) 中得到修复
2021-06-20 21:31:12