在heroku上部署的MERN App上获取404

时间:2020-02-21 05:08:39

标签: node.js reactjs heroku mern

我尝试在Heroku上部署我的MERN堆栈应用程序,但是现在尝试启动该应用程序时我得到了404。日志相同如下:

2020-02-21T04:43:37.862088+00:00 heroku[router]: at=info method=GET path="/" host=task-reminder25.herokuapp.com request_id=d549deca-d280-4db4-8549-3579082e903c fwd="45.118.159.123" dyno=web.1 connect=0ms service=3ms status=404 bytes=403 protocol=https
2020-02-21T04:43:37.862479+00:00 app[web.1]: 10.63.151.139 - - [21/Feb/2020:04:43:37 +0000] "GET / HTTP/1.1" 404 191 "https://dashboard.heroku.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"

我也添加了环境变量。 我的index.js(Backend)的内容是:

//Serve static assets in production
if(process.env.NODE_ENV==='production') {
    //Set static folder
    app.use(express.static(`../client/build`));
    app.get('*',(req,res)=>{
        res.sendFile(path.resolve(__dirname, '..','client', 'build','index.html'))
    });

} 

Node

如果有人能帮助我解决这个问题,那就太好了。 编辑:如果有人想看一下,我已经将该链接添加到我的Github存储库中。

1 个答案:

答案 0 :(得分:0)

尝试删除nodemon(如果已安装)。

 "scripts": {
    "start": "node app.js" // node your main file name
  },