gpt4 book ai didi

node.js - Heroku 上出现 H10 "App crashed"错误,但描述性不强

转载 作者:太空宇宙 更新时间:2023-11-04 01:43:42 26 4
gpt4 key购买 nike

我不断收到以下错误:

2018-09-05T21:53:30.439186+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=still-mesa-69894.herokuapp.com request_id=51732ef5-7b89-4629-900e-8a73c927d07f fwd="137.146.137.3
0" dyno= connect= service= status=503 bytes= protocol=https
2018-09-05T21:53:30.908139+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=still-mesa-69894.herokuapp.com request_id=32608dfd-2314-48e6-9696-8fa2fcd02d13 fwd="13
7.146.137.30" dyno= connect= service= status=503 bytes= protocol=https

这是我的 package.json。

{
"name": "myfinalproject",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:1337",
"dependencies": {
"@material-ui/core": "^1.4.2",
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.3",
"express-session": "^1.15.6",
"mapbox-gl": "^0.47.0",
"material-ui": "^0.20.1",
"mdi-material-ui": "^5.2.0",
"mongoose": "^5.2.6",
"morgan": "^1.9.0",
"node-geocoder": "^3.22.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"prop-types": "^15.6.2",
"react": "^16.4.2",
"react-bootstrap": "^0.32.1",
"react-dom": "^16.4.2",
"react-geolocation": "^1.0.4",
"react-mapbox-gl": "^3.8.0",
"react-navigation": "^2.9.3",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"react": "react-scripts start",
"dev": "npm run server | react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"engines": {
"node": "8.11.2",
"npm": "6.2.0"
},
"devDependencies": {
"nodemon": "^1.17.5"
}
}

我的 server.js 中有这些

const express = require('express');
app.use(express.static(path.join(__dirname, 'build')));

app.get('/', function (req, res) {
var port = server.address().port;

// res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

app.listen(process.env.PORT || 1337);

我认为“/”路线有错误,但不知道为什么。它可以在我的本地主机上运行。这是一个 react 应用程序。我是 Heroku 的新手。我使用的是 Windows PC,而不是 Mac。

最佳答案

我不确定您为什么要访问 app.get 方法内的端口,但您必须执行以下操作才能解决该问题。

app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

//Assign port like this
const port = process.env.PORT || 1337;

app.listen(port, () => {
console.log("App is running on port ", this.address().port);
});

检查这个Heroku official help guide了解更多详情。

PS:我用箭头函数替换了普通函数。但如果您仍然想使用正常功能,也可以。

关于node.js - Heroku 上出现 H10 "App crashed"错误,但描述性不强,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52195574/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com