我收到了一个申请错误。这是一个错误:
2020-10-29T17:02:02.043156+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=helloworld-mastercard.herokuapp.com request_id=640ea1df-832d-41a2-ab8a-90ba603398e9 fwd="37.228.208.88" dyno= connect= service= status=503 bytes= protocol=https
2020-10-29T17:02:05.327275+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=helloworld-mastercard.herokuapp.com request_id=f1f3fe21-e1e5-4a39-9ee5-bf078ff39266 fwd="37.228.208.88" dyno= connect= service= status=503 bytes= protocol=https
我在youtube上学习了如何做到这一点的教程。我添加了一个包含以下内容的server.js:
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);
我的package.json如下:
{
"name": "helloworld",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.5",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"express": "^4.17.1",
"express-favicon": "^2.0.1",
"path": "^0.12.7",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
我已经完成了npm运行构建,我非常困惑我哪里出错了
发布于 2020-10-29 09:31:02
Heroku需要一个文件调用Procfile来完成构建和运行过程。
在您的示例中,在应用程序的主文件夹中创建一个名为Procfile的文件,并添加以下内容:
web: node server.js
您可以阅读更多关于Procfile的这里。
此外,要在Heroku上运行构建脚本,需要将其添加到package.json文件的脚本部分,如下所示:
"scripts": {
"start": "node server.js", // serves the application
"heroku-postbuild": "webpack -p" // runs after installation
}
有关如何将webpack应用程序部署到Heroku的详细信息,请参阅本链接。
解释性 Heroku会自动安装所有依赖项,并在为应用程序提供服务之前继续执行构建后操作。在此构建后操作中,我们对js文件进行生产捆绑,并允许Heroku通过运行start命令启动应用程序。
https://stackoverflow.com/questions/64596114
复制相似问题