Skip to content

Instantly share code, notes, and snippets.

@readikus
Last active December 5, 2020 19:09
Show Gist options
  • Select an option

  • Save readikus/2f9a5dc00cfa49be4ba5db3207788d7e to your computer and use it in GitHub Desktop.

Select an option

Save readikus/2f9a5dc00cfa49be4ba5db3207788d7e to your computer and use it in GitHub Desktop.
Steps for deploying a web app on AWS (or similar) using React, Express, Nginx and Docker

Deploying a React webapp on AWS (or similar) using React, Express, Nginx and Docker

It's important to understand the big piocture of what we are trying to do with this. The diagram below shows the path http requests come in from the browser when trying to get data from the web app. If we don't understand this overall path and what we are trying to achieve, we risk getting stuck cargo coding bits and pieces from various tutorials and don't really know how to fix issues/keep up to date.

Before getting into this, make sure you completely understand this https://flaviocopes.com/http-request/

Infrastructure diagram - react, express, nginx, docker, aws

Milestones

With each step, be very careful to ensure it is repeatable and designed to pull in the latest LTS (long term support) version of the dependancies. No good needing to update the docker configuration each time a new version of node, nginx, your choosen linux distro comes out.

  1. Get React running with a stand alone server as per https://create-react-app.dev/docs/deployment/

  2. Make sure react and express still talk to each other

  3. Make a list of the URL patterns which are being served from your backend app (i.e. URLs should start with patterns like /api/* and /images/*). This is so we can create routing rules to know if requests from the browser should go to the front end or the back end.

  4. Get nginx running as a reserve proxy. Basically nginx is your butler, that http requests on port 80 (the default http port), and looks at the URL, if it is /api* or /images*, directs the request to the backend (i.e. express), otherwise send it to the front end (i.e. react).

  5. Get nginx, react and express all running in a docker container.

  6. Deploy the latest code to AWS, build and run the container and check it's getting served up on port 80. Ensure port 80 is open.

Next Steps:

  • Lint your code!
  • Code review from hell.
  • Run over https...using letsencrypt to handle SSL certificates.
  • Make work with Auth0
  • Use postgres to manage your data
  • Add unit (Jest) and acceptance tests (Nightwatch)
  • Get your first coding job!
  • Host images in S3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment