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

4

我正在尝试在某个文件上设置 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" : "*"
    } ]
  }]
}

然而它从未被设置:https://curious-athlete-131013.firebaseapp.com/bundle.js

1个回答

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" : "*"
      }]
    }]
  }
}

"

可以通过在firebase.json文件中的hosting部分定义标题部分来指定自定义、文件特定的标题:

- Firebase文档"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接