Firebase 托管部署错误 HTTP 400 错误

Firebase Hosting Deployment Error HTTP 400 Error

我试图在解决一些问题后在 firebase 上重新部署我的 React 应用程序。但是重新部署会出错。不确定是什么问题。

我也尝试查看其他帖子中提供的答案,但对我没有任何帮助。

firebase.json详情如下:

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [{
      "source": "**",
      "destination": "/index.html",
      "headers": [{
        "key": "Cache-Control",
        "value": "max-age=0"
      }]
    }]
  }
}

Error: HTTP Error: 400, hosting.rewrites[0] is not exactly one from [subschema 0],[subschema 1]

这是我第一次遇到这个错误。所以不知道是什么问题。

好的,所以问题是 headers。删除它解决了这个问题。我把它放在那里,这样当用户在网站更新后刷新网站时,网站就会重新加载。它以前工作正常。不知道是什么问题。如果其他人可以解决此问题或告诉我我做错了什么,将保持开放状态。 :)

Headers 选项查看 rewrites 参数内的行。相反,您需要搬出:

"hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [{
      "source": "**",
      "destination": "/index.html"
    }],
    "headers": [{
        "key": "Cache-Control",
        "value": "max-age=0"
    }]
  }

您缺少 headers 的 source 选项,看看我是如何构造我的:

{
  "hosting": {
    "public": "build",
    "headers": [
      {
        "source": "/service-worker.js",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "no-cache"
          }
        ]
      }
    ]
  }
}

关于如何构造 headers 的文档是 here

"hosting": {
"public": "build",
"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
],
"rewrites": [{
  "source": "**",
  "destination": "/index.html"
}],
"headers": [{
    "key": "Cache-Control",
    "value": "max-age=0"
}]

}