【问题标题】:Firebase hosting does not send custom HTTP headersFirebase 托管不发送自定义 HTTP 标头
【发布时间】:2018-02-07 06:28:06
【问题描述】:

根据Firebase Hosting docs,我应该能够在从服务器收到的响应上设置自定义标头。我正在尝试在所有 html 文件上设置 X-Frame-Options 标头,但服务器根本不想发送此标头!这是我的 firebase.json 文件,如果我做错了什么请告诉我:

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [
      {
        "source": "**/*.html",
        "headers": [
          {
            "key": "X-Frame-Options",
            "value": "SAMEORIGIN"
          }
        ]
      }
    ]
  }
}

【问题讨论】:

    标签: firebase firebase-hosting firebase-cli


    【解决方案1】:

    我刚刚在同一个问题上经历了很多试验和错误。我注意到firebase documentation 中有一小部分:

    Hosting 与原始请求路径匹配的源值,不考虑任何重写规则

    如果你的设置和我的一样,你的 firebase.json 文件中可能有这个:

      "rewrites": [{
        "source": "**",
        "destination": "/index.html"
      }]
    

    但是,虽然您可能返回 index.html,但原始请求路径只是“/”,因此在您的标头部分使用:

    "source": "/"
    

    这对我有用。

    【讨论】:

    • 感谢您的提示。虽然我不再使用这个项目了,但这对将来会有帮助。
    【解决方案2】:

    经过反复试验,我发现了问题所在。这一切都是在我尝试使用https://my-project.firebaseapp.com 加载 index.html 时进行的——这显然不会触发标题。我必须在 URL 的末尾明确添加 /index.html 才能使其工作:https://my-project.firebaseapp.com/index.html。我不应该这样做,但这就是问题所在。所以问题仍然存在 - 如何让 firebase 配置与隐含的 index.html 匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-27
      • 2014-07-07
      • 2015-08-29
      • 2018-09-13
      • 1970-01-01
      相关资源
      最近更新 更多