部署React / Node应用后,从Heroku不断收到错误“ App崩溃”方法=“ GET path =” /“

时间:2019-10-31 13:47:03

标签: node.js reactjs express

所以我搜索了几个小时,似乎找不到我要的答案。

我正在尝试将一个简单的React / Express / Node应用程序部署到Heroku,并且似乎无法使其正常工作。

这是我的文件:

server.js:

const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 5000;

app.listen(port, () => console.log(`Listening on port ${port}`));

app.use(express.static(path.join(__dirname, '/client/dist')));

app.get('/', (req, res) => {
  res.send('working');
});

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

package.json脚本(服务器端)

  "scripts": {
    "client": "cd client && yarn start",
    "server": "nodemon server.js",
    "dev": "concurrently \"yarn server\" \"yarn client\"",
    "start": "node server.js",
    "heroku-postbuild": "cd client && yarn && yarn build"
  }

package.json脚本(客户端):

  "scripts": {
    "start": "webpack-dev-server --mode development",
    "build": "webpack --mode production"
  },
  "proxy": "http://localhost:5000"
}

这是我从Heroku中得到的错误:

2019-10-31T13:38:05.115627+00:00 heroku[web.1]: Restarting
2019-10-31T13:38:05.152127+00:00 heroku[web.1]: State changed from up to starting
2019-10-31T13:38:12.160678+00:00 heroku[web.1]: Starting process with command `npm start`
2019-10-31T13:38:14.166605+00:00 app[web.1]:
2019-10-31T13:38:14.166642+00:00 app[web.1]: > virtual-travel-guide-wp@1.0.0 start /app
2019-10-31T13:38:14.166645+00:00 app[web.1]: > node server.js
2019-10-31T13:38:14.166647+00:00 app[web.1]:
2019-10-31T13:38:14.322414+00:00 app[web.1]: Listening on port 31450
2019-10-31T13:38:14.602+00:00 heroku[web.1]: State changed from starting to up
2019-10-31T13:38:10.563066+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=virtual-travel-assistant.herokuapp.com request_id=ce3e1560-f116-4f09-9f1f-abd61c02d8e2 fwd="73.195.16.201" dyno= connect= service= status=503 bytes= protocol=https
2019-10-31T13:38:21.489142+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=virtual-travel-assistant.herokuapp.com request_id=812db414-9875-450e-afc5-6cf919ae17ff fwd="73.195.16.201" dyno= connect= service= status=503 bytes= protocol=https
2019-10-31T13:38:06.440817+00:00 heroku[web.1]: Process exited with status 143

任何帮助将不胜感激。现在后端没有任何反应,我只是想显示我的React应用。

0 个答案:

没有答案