How to deploy separated frontend and backend?

18,667

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
Share:
18,667

Related videos on Youtube

Yen Sheng
Author by

Yen Sheng

Updated on June 04, 2022

Comments

  • Yen Sheng
    Yen Sheng almost 2 years

    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.

  • Hansen W
    Hansen W about 6 years
    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?
  • GG.
    GG. about 6 years
    "just one instance since I already have CDN" - yes just one. It's the CDN's job to make it scale.
  • titus
    titus over 4 years
    What about CORS and/if using httpOnly cookies?
  • tanguy_k
    tanguy_k about 4 years
    What about SSR (Next.js for example)? Your frontend then needs to run Node.js.
  • Daniel
    Daniel about 3 years
    @GG., this is a great answer. Any documentation out there on how to get that backend Heroku talking to the frontend on S3 + Cloudfront?
  • Jahir
    Jahir about 3 years
    Good summary. The CORS issue needed some mentions though
  • Olgun Kaya
    Olgun Kaya over 2 years
    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.
  • GG.
    GG. over 2 years
    @OlgunKaya you don't need a web server to serve a static file.