如何在 Firebase 文件上设置 Access-Control-Allow-Origin

Tol*_*oli 4 firebase firebase-hosting

我正在尝试设置Access-Control-Allow-Origin*某个文件。

这是我的 firebase.json 文件:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "headers": [ {
    "source" : "bundle.js",
    "headers" : [ {
      "key" : "Access-Control-Allow-Origin",
      "value" : "*"
    } ]
  }]
}
Run Code Online (Sandbox Code Playgroud)

然而它永远不会被设置:https ://curious-athlete-131013.firebaseapp.com/bundle.js

Joh*_*ell 5

尝试将标头嵌套在托管下方,而不是作为它自己的顶级节点:

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [{
        "source": "**",
        "destination": "/index.html"
    }],
    "headers": [{
      "source" : "bundle.js",
      "headers" : [{
        "key" : "Access-Control-Allow-Origin",
        "value" : "*"
      }]
    }]
  }
}
Run Code Online (Sandbox Code Playgroud)

“可以通过在 firebase.json 文件中的托管中定义headers 部分来指定自定义、文件特定的标头:” - Firebase 文档