Firebase 托管 400 错误请求
Firebase Hosting 400 Bad Request
我正在尝试为我的项目设置 firebase 托管。我已经部署到 https://budyeez-app.web.app/
我正在使用 vue.js 框架构建我的应用程序,因此我的 public 文件夹中有一个 index.html 文件。所有 vue 内容都加载到该文件中以进行渲染。在 localhost 上一切正常,但是当我尝试在 Firebase none 上托管该站点时,将加载 vue 内容。如果我将内容直接写入 index.html 文件,它将加载,这解释了为什么页面标题有效。有想法该怎么解决这个吗?
Explorer
web_app/firebase.json
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
web_app/public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>Budyeez</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
<script src="https://kit.fontawesome.com/3797ae5e09.js" crossorigin="anonymous"></script>
</head>
<body>
<h3>This is a test</h3>
<noscript>
<strong>We're sorry but web_app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
将您的 firebase.json
更新为以下内容(编辑掉我的评论):
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "dist", // <-- CHANGED: hosting deploy directory to Vue's build directory
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"predeploy": [
"npm run build" // <-- CHANGED: Before deploying, automatically build Vue project
]
},
"storage": {
"rules": "storage.rules"
}
}
我正在尝试为我的项目设置 firebase 托管。我已经部署到 https://budyeez-app.web.app/
我正在使用 vue.js 框架构建我的应用程序,因此我的 public 文件夹中有一个 index.html 文件。所有 vue 内容都加载到该文件中以进行渲染。在 localhost 上一切正常,但是当我尝试在 Firebase none 上托管该站点时,将加载 vue 内容。如果我将内容直接写入 index.html 文件,它将加载,这解释了为什么页面标题有效。有想法该怎么解决这个吗?
Explorer
web_app/firebase.json
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
web_app/public/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>Budyeez</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
<script src="https://kit.fontawesome.com/3797ae5e09.js" crossorigin="anonymous"></script>
</head>
<body>
<h3>This is a test</h3>
<noscript>
<strong>We're sorry but web_app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
将您的 firebase.json
更新为以下内容(编辑掉我的评论):
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"hosting": {
"public": "dist", // <-- CHANGED: hosting deploy directory to Vue's build directory
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"predeploy": [
"npm run build" // <-- CHANGED: Before deploying, automatically build Vue project
]
},
"storage": {
"rules": "storage.rules"
}
}