我不断收到以下错误:
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的初学者。我使用PC Windows,而不是Mac。
答案 0 :(得分:0)
我不确定您为什么要访问app.get方法中的port,但这是解决该问题所要做的事情。
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:我用箭头功能替换了正常功能。但是,如果您仍然想使用常规功能,则可以。