ajs*_*ack 4 javascript heroku reactjs
部署时,heroku告诉我我的构建成功,但是我得到Failed to load resource: the server responded with a status of 400 (Bad Request)了favicon和manifest,以及Manifest: Line: 1, column: 1, Unexpected token.Lighthouse告诉我它根本没有链接到manifest.json。我不确定这些是否相关,如果是这种情况,我将提出一个新问题。我在节点服务器上使用Reactjs。
这是我的server.js
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const PORT = process.env.PORT || 3001;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "./client/public/index.html"));
});
app.listen(PORT, function() {
console.log(` ==> API Server now listening on PORT ${PORT}!`);
});
Run Code Online (Sandbox Code Playgroud)
这是我的index.html的标题
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
Run Code Online (Sandbox Code Playgroud)
让我知道您是否需要更多信息,如果这是重复问题,或者这些问题无关,那么我可以采取相应措施。
我部署我以后有同样的问题react-app上firebase-hosting
manifest.json并在google-chrome DevTools中favicon.ico提供400 Bad Request了network标签
运行后firebase init,如果您在firebase询问时未键入build的情况下,要用作公共目录?(公共),
那么您将必须转到firebase.json根项目文件夹中的文件并手动更改托管->“ public”:“ build”
会是这样的
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
如果你deploying react app on firebase选中这个和这个的也有用。
| 归档时间: |
|
| 查看次数: |
1640 次 |
| 最近记录: |