react + docker, part 1
public repo for this post: https://github.com/lombardo-chcg/dockerized-create-react-app
–
The create-react-app from Facebook is a fantastic way to kick start a UI project built with React. I had a use case to deploy a basic React app using AWS EC2 Container Service, so I decided to Dockerize a create-react-app. Here’s how it went down.
Basic workflow
- create a simple server using express that will serve up the static UI content based based on an http request
- After finishing up the UI work, use the
create-react-app
build script to create a “productionized” version of the React app - combine both pieces into a docker image
Part 1: basic HTTP server
The create-react-app documentation is some of the best I’ve seen. They already included a basic node express server implementation, so we will just build on that to suit our needs.
Now here’s a basic Express server:
inside main.js
:
Now this node server process is all ready to start handling requests for the single-page app itself, and also for any api calls it may make.
Next time, we’ll set up our Dockerfile and build an image.