Firebase Hosting未获取到期标头

问题描述 投票:0回答:1

我的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

请问有什么事吗?

firebase firebase-hosting
1个回答
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
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.