微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试将 MERN 应用程序部署到 Heroku 时出错

如何解决尝试将 MERN 应用程序部署到 Heroku 时出错

我正在尝试将 MERN 堆栈应用程序部署到 Heroku,除了登录页面外,一切正常。 我尝试了所有可能的解决方案,但没有任何效果。 这是我的应用程序 landing page,它显示蓝色屏幕,顶部有一个按钮,如果尝试导航到不同的路线,如 /contact/plans,它工作正常。 我检查了日志和网络请求一切正常 200 状态。

enter image description here

我在我的机器上测试了该应用程序,它按预期工作。

enter image description here

在 Heroku 上显示蓝屏

enter image description here

这是我的 server.js 代码

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

这是我的脚本

"scripts": {
    "client-install": "npm install --prefix frontUI/client","start": "node server.js","server": "nodemon server.js","client": "npm start --prefix frontUI/client","dev": "concurrently \"npm run server\" \"npm run client\"","heroku-postbuild":
      "NPM_CONfig_PRODUCTION=false npm install --prefix frontUI/client && npm run build --prefix frontUI/client"
  },

我的着陆页路线

<Route
        exact
        path="/"
        render={matchProps => (
          <WithLayout
            {...matchProps}
            component={ServicesView}
            layout={MainLayout}
          />
        )}
      />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。