如何将Strapi后端和ReactJS前端部署到单个Heroku应用程序 [英] How to deploy Strapi backend and ReactJS frontend to a single Heroku app

查看:89
本文介绍了如何将Strapi后端和ReactJS前端部署到单个Heroku应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何受支持的方法如何将Strapi后端和ReactJS前端部署到单个Heroku应用程序中?

Is there any supported way how to deploy a Strapi backend and a ReactJS frontend into a single Heroku app?

我已经成功部署了Strapi后端,但是完全无法理解或找到有关如何部署前端的教程.

I have successfully deployed the Strapi backend, but am completely unable to understand or find a tutorial on how to deploy the front end.

推荐答案

如果有人想知道穆罕默德·艾哈迈德(Muhammad Ahmad)的解决方案是否可行-是的,它可行.

If somebody wants to know if Muhammad Ahmad's solution works - yes, it works.

最初,我专门使用MERN堆栈,并使用了两个文件夹-一个用于客户端,另一个用于服务器.根目录只有package.json.在Heroku上一切正常,所以我没想到很难将后端切换到Strapi ...

Initially, I worked exclusively with the MERN stack and used two folders - one for the client, the other for the server. Only package.json was at the root. Everything worked fine on Heroku, so I didn't expect to find it difficult to switch the backend to Strapi...

然后,我决定尝试将服务器端(Express)替换为Strapi.之后,存在将整个案例部署到Heroku并在单个Heroku应用程序上运行它的问题.

Then I decided to try to replace the server side (Express) to Strapi. After that, there was a problem of deploying this whole case to Heroku and running it on single Heroku application.

因此,项目结构为:

/root 
      - /client (React UI)
      - /server (Strapi)
      - package.json

为了使整个事情协同工作,有必要对内部的一些更改进行修改

In order to make the whole thing work together, it is necessary to amend a little change inside

./middlewares/serve-react/index.js:

 const staticDir = path.resolve(strapi.dir, clientBuildPath || strapi.config.paths.static);

其中 clientBuildPath ../client/build .

这篇关于如何将Strapi后端和ReactJS前端部署到单个Heroku应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆