Firebase Hosting未获取到期标头

时间:2018-02-05 20:56:03

标签: firebase firebase-hosting

我的firebase.json文件如下所示:

{
  "hosting": {
      "public": "public",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "headers": [{
      "source": "**",
      "headers": [{
        "key": "Cache-Control",
        "value": "max-age=960000"
      }]
      }],
      "rewrites": [ {
      "source": "**",
      "destination": "/index.html"
      }],
    "source" : "404.html",
    "headers" : [ {
      "key" : "Cache-Control",
      "value" : "max-age=960000"
    }],
    "headers": [ {
    "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
    "headers" : [ {
      "key" : "Access-Control-Allow-Origin",
      "value" : "*"
    } ]
    }],
    "cleanUrls": true,
    "trailingSlash": false
  }
}

现在检查浏览器中的资产,我看不到对发送的过期标题产生任何影响。

enter image description here

请问有什么问题?

1 个答案:

答案 0 :(得分:5)

您的配置格式错误 - 您的headers配置中有多个顶级hosting。它应该看起来更像:

{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "headers": [
      {
        "source": "**",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=960000"
          }
        ]
      },
      {
        "source": "404.html",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=960000"
          }
        ]
      },
      {
        "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
        "headers": [
          {
            "key": "Access-Control-Allow-Origin",
            "value": "*"
          }
        ]
      }
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "cleanUrls": true,
    "trailingSlash": false
  }
}