【问题标题】:Deploy on Heroku found error: GET 502 Bad Gateway favicon.ico在 Heroku 上部署发现错误:GET 502 Bad Gateway favicon.ico
【发布时间】:2021-09-20 21:03:15
【问题描述】:

我已经按照本教程和一些类似的教程进行操作,但它向我显示了标题错误。

https://dev.to/hawacodes/deploying-a-mern-app-with-heroku-3km7

我也在heroku上放了env config var

这是我的实践项目github https://github.com/NDK2020/sheyshop

还有我当前的 Heroku 应用 https://practice-sheyshop.herokuapp.com/

我已经尝试了所有方法,但没有成功。我可以看到网站在开发环境中加载,然后在几秒钟内屏幕空白,在 Firefox 中打开网络选项卡,它说: error Image

来自heroku的日志 Log image

【问题讨论】:

    标签: heroku deployment get mern favicon


    【解决方案1】:

    我想我已经找到了答案,在我的 server.ts 中,我必须将此代码块放在路由声明之后。从此

    if (process.env.NODE_ENV === "production") {
      console.log("PRODUCTION MODE ACTIVE");
      //app.use('/', express.static("/client/build"));
      app.use(express.static("./client/build"));
      app.get('*', (req: any, res: any) => {
        res.sendFile(path.resolve(__dirname, './client/build','index.html'));
      })
    }
    
    app.use('/api/products/', productRoute)
    app.use('/api/users/', userRoute)
    app.use('/api/orders/', ordersRoute);
    

    到这里

    app.use('/api/products/', productRoute)
    app.use('/api/users/', userRoute)
    app.use('/api/orders/', ordersRoute);
    
      
    if (process.env.NODE_ENV === "production") {
      console.log("PRODUCTION MODE ACTIVE");
      //app.use('/', express.static("/client/build"));
      app.use(express.static("./client/build"));
      app.get('*', (req: any, res: any) => {
        res.sendFile(path.resolve(__dirname, './client/build','index.html'));
      })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 2021-03-31
      • 2021-10-02
      • 2014-05-12
      相关资源
      最近更新 更多