使用Heroku部署React应用+ Node服务器

问题描述:

我想部署一个项目(React应用程序+节点服务器),但是我是新手,

I want to deploy a project (React app + Node server), but I'm new to deployment,

我想知道:我是否需要

当前,我有1个Github存储库,其中的文件夹为 frontend和另一个后端,

Currently, I have 1 Github repository with a folder "frontend" and an other "backend",

我想将我的React应用放在-> nameofmyapp.herokuapp.com
上,并将Node服务器放在-> api- nameofmyapp.herokuapp.com,

I want to have my React app on -> nameofmyapp.herokuapp.com and the Node server on -> api-nameofmyapp.herokuapp.com,

如果有人有想法...,谢谢

If someone got ideas... Thanks

虽然从理论上讲这不是问题,但我建议出于某些原因(例如额外的延迟和连接问题以及您面临的路径问题)考虑将内容保留在一个域中。在我看来,理想情况下,您只想为应用程序名称添加后端或类似名称的前缀,在这种情况下,我只考虑在我控制的域(即mydomain.com和backend.mydomain.com。在Heroku上进行开发时,由于每个网站或应用都是独立的,并且实际上并没有打算在它们可以肯定的情况下一起工作,因此该模型可能会很棘手。考虑在应用程序上为后端设置单独的路由和后端端点,类似于前端登录,然后当您完成应用程序开发并满意时,可以注册域名并将其指向您的应用程序并指向子域,即后端.mysite.com或login.mysite.com到Heroku上的端点,即mysite.com/backend。除非您有特殊的原因要用单独的源代码控制和URL将它们分成自己的存储库,否则可能会使调试工作变得更加困难。抱歉,我想念您的意思。大多数网络托管公司应允许您免费或免费注册子域或虚构的domian,因为您拥有主domian。只是一些注意事项。

While in theory that's not a problem, I would suggest maybe considering keeping things on one domian for reasons such as additional latency and connection trouble as well as path issues such as you are facing. It would seem to me that you would ideally just like to prefix the name of your app with 'backend' or similar and in such a case I would just consider setting up a sub domain on a domain which I had control ie mydomain.com and backend.mydomain.com. While developing on Heroku this model could prove to be tricky as each 'site' or app is separate and not actually intended to work together while they most certainly could. Consider setting up separate routes and an endpoint for 'backend' on your app, similar to your frontend login, then when you are finished developing your app and happy you could register your domain name and point it to your app and point a subdomain ie backend.mysite.com or login.mysite.com to your endpoint on Heroku ie mysite.com/backend. Unless you have a specific reason for separating them into their own repos with separate source control and urls, it might make debugging things much harder. Apologies if I missed your point. Most web hosting companies should allow you to register a subdomain or vanity domian free or charge because you own the primary domian. Just some considerations.