25

I am developing a new project with react/express as the frontend and loopback as the backend api. I have separated both of them in my development environment with different ports.

How should I deploy them in production?

  1. Hosting on a same server - separate the backend with a different sub-domain?

  2. Hosting on 2 different servers - seems impossible to use back the same domain.

antzshrek
  • 9,276
  • 5
  • 26
  • 43
Yen Sheng
  • 695
  • 1
  • 12
  • 28

1 Answers1

49

I just answered a related question for AWS.

You can deploy

You can set different subdomains on different hosts, e.g.

  • app.domain.com on GitHub Pages
  • api.domain.com on Heroku
Community
  • 1
  • 1
GG.
  • 21,083
  • 14
  • 84
  • 130
  • Great answer, thanks, helped me a lot. Just have an additional question. In this case, how many instances of containers should I use for frontend and backend? I know for the backend since it accepts a lot of incoming requests, a load balancer and several instances should be deployed. But how about frontend, should I use equal amount or just one instance since I already have CDN? – Hansen W Mar 20 '18 at 01:22
  • "just one instance since I already have CDN" - yes just one. It's the CDN's job to make it scale. – GG. Mar 20 '18 at 02:32
  • 2
    What about CORS and/if using httpOnly cookies? – titus Dec 27 '19 at 22:55
  • 1
    What about SSR (Next.js for example)? Your frontend then needs to run Node.js. – tanguy_k Apr 16 '20 at 14:08
  • @GG., this is a great answer. Any documentation out there on how to get that backend Heroku talking to the frontend on S3 + Cloudfront? – Daniel Feb 07 '21 at 04:20
  • Good summary. The CORS issue needed some mentions though – Jahir Mar 11 '21 at 19:04
  • I don't know why people don't want to use or utilize nginx approach ? Just deploy your frontend on an nginx/httpd etc.. then apply proxies as per your APIs towards related endpoints. – Olgun Kaya Nov 09 '21 at 14:01
  • @OlgunKaya you don't need a web server to serve a static file. – GG. Nov 09 '21 at 16:39