如何在Firebase文件上设置Access-Control-Allow-Origin [英] How do you set Access-Control-Allow-Origin on Firebase files

查看:45
本文介绍了如何在Firebase文件上设置Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在特定文件上将Access-Control-Allow-Origin设置为*.

I am trying to set Access-Control-Allow-Origin to * on a certain file.

这是我的firebase.json文件:

This is my firebase.json file:

{
  "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

However it never gets set: https://curious-athlete-131013.firebaseapp.com/bundle.js

推荐答案

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

Try nesting the headers underneath hosting rather than as it's own top level node:

{
  "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文件的在托管范围内定义标头部分来指定自定义的,特定于文件的标头:"-

"Custom, file specific, headers can be specified by defining a headers section within hosting in the firebase.json file:" - Firebase Docs

这篇关于如何在Firebase文件上设置Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆