Reactjs 部署只对Heroku作出反应

Reactjs 部署只对Heroku作出反应,reactjs,heroku,Reactjs,Heroku,一般来说,我不熟悉react/web开发,我想知道您是否可以将react单独部署到Heroku。部署NodeJS需要吗?我使用了npx create react应用程序,它在本地工作,但在尝试将默认创建部署到Heroku时,我遇到了错误: 2020-06-27T07:20:18.595194+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host

一般来说,我不熟悉react/web开发,我想知道您是否可以将react单独部署到Heroku。部署NodeJS需要吗?我使用了npx create react应用程序,它在本地工作,但在尝试将默认创建部署到Heroku时,我遇到了错误:

2020-06-27T07:20:18.595194+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-retreat-92346.herokuapp.com request_id=3f99711a-9c2f-4257-9845-c7f0f137ebe8 fwd="73.189.100.93" dyno= connect= service= status=503 bytes= protocol=https

此外,是否有关于部署概述以及React+Node+webpacks如何协同工作的指南。我很难理解所有东西是如何连接的。

为了部署react,您需要使用node。以下是在heroku上组合node、react和deploy的步骤

步骤1:使用express创建node.js服务器,并在服务器主文件(例如app.js)中编写一些必要的代码,如下所示

 const express = require('express');
 const app = express();

 //Below code is to point to your react build folder which you will keep inside server folder inside client folder

 let root = path.join(__dirname, 'client/build/')
 app.use(express.static(root))
 
 //this is the routing which will redirect your server url to react build file
 app.get("*",(req,res)=>{
    res.sendFile(path.join(__dirname, '/client/build/index.html'));
 })

 app.listen(process.env.PORT || 8080);
步骤2:在app.js文件所在的服务器文件夹中创建客户端文件夹,并将react创建的构建文件夹放置在客户端文件夹中


步骤3:在将正确的存储库指向git或bitbucket或gitlab后,使用git push heroku master将其部署到heroku。部署后,react应用程序将在此服务器url上运行。

感谢@Anku提供的帮助。