【问题标题】:Getting 404 on a MERN App deployed on heroku在部署在 heroku 上的 MERN 应用程序上获取 404
【发布时间】:2020-06-05 12:31:41
【问题描述】:

我尝试在 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'))
    });

} 

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

【问题讨论】:

标签: node.js reactjs heroku mern


【解决方案1】:

如果您已安装,请尝试删除 nodemon。

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

【讨论】:

  • 但它是作为开发依赖安装的,因此在部署时修剪开发依赖并不重要。如果我错了,请纠正我。
  • 请删除并检查。据我所知,Nodemon 无法在 Heroku 中工作
猜你喜欢
  • 2021-03-01
  • 1970-01-01
  • 2021-03-03
  • 2021-01-31
  • 1970-01-01
  • 2018-06-25
  • 2021-09-02
  • 2022-12-10
  • 1970-01-01
相关资源
最近更新 更多