Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy separated frontend and backend?

Tags:

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.

like image 357
Yen Sheng Avatar asked Dec 20 '16 17:12

Yen Sheng


People also ask

Can I deploy frontend and backend separately?

A common application architecture is to host a front-end (user-interfacing) application and back-end (data-serving) application separately from each other. The goal is separation of concerns and therefore an increased ease in continuous integration between separate teams.

Can I deploy frontend and backend on same server?

You can't start both on the same one and if they are apart, it's impossible for the frontend code to access the backend endpoints. Fear not. If you really want to run both servers, you have to make sure that both are accessible through the same port.

How do you run frontend and backend together?

In the package. json file, edit the script: "scripts": { "server": "npm run dev --prefix server", "client": "npm start --prefix client", "dev": "concurrently \"npm run server\" \"npm run client\"" }, And, npm run dev you can start both at the same time.


1 Answers

I just answered a related question for AWS.

You can deploy

  • your frontend on a static hosting service and a CDN

    • AWS S3 + AWS CloudFront
    • Google Cloud Storage + Google Cloud CDN
    • GitHub Pages + CloudFlare
    • Now
    • Surge
    • Netlify
    • etc
  • your backend on a cloud computing service

    • AWS Elastic beanstalk or AWS EC2
    • Google App Engine
    • Now
    • Heroku
    • etc

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

  • app.domain.com on GitHub Pages
  • api.domain.com on Heroku
like image 178
GG. Avatar answered Sep 17 '22 15:09

GG.