我正在尝试将某个文件的 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
最佳答案
尝试将 header 嵌套在托管下方,而不是作为它自己的顶级节点:
{
"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 文件中托管中定义 header 部分来指定自定义、文件特定的 header :” - Firebase Docs
关于firebase - 如何在 Firebase 文件上设置 Access-Control-Allow-Origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151896/