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

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

但是它永远不会被设置: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/

相关文章:

android - 如何在 android 中生成 firebase 注册 token

firebase - 使用 Geofire + Firebase 过滤结果

firebase 托管未显示正确的文件内容

terminal - firebase 托管 - 终端挂起等待身份验证

android - 如何使其工作NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);

javascript - 将新数据推送到 firebase 数据库时设置自定义数字键

javascript - 如果 setState 不能使用,那么什么是

Java 通过键名从对象中获取值

node.js - 如何在 firebase 上使用带有 Handlebars 模板引擎的 Node js 托管我的 Web 应用程序

使用 Firebase 托管部署的 Flutter Web 不尊重 Safari 中的刷新