Create React App with Node Backend

Noen apper trenger både frontend og backend, der backenden kanskje er skrevet i node.js og frontenden er create app. Disse kan bruke denne konfigurasjonen. Det er en avart av Create React App

Mange av våre ventures bruker create react app direkte og har ingen backend. For disse kan du bruke disse filene.

Note

Denne er basert på at du bruker create react app med typescript og yarn. Om det ikke stemmer, så må du lese kommentarene for å gjøre noen endringer.

.dockerignore

Ignorer noen filer som ikke vi vil skal være med i docker-bygget. Dette gjør at det går raskere å teste lokalt med docker build ., og det gjør også lokalt bygg likere det som skjer i iterapp.

.dockerignore
Dockerfile
node_modules

Dockerfile

# This is the build-container, we need node to build
FROM node:10 as build

# Set NODE_ENV to production to create a production-build of react
ENV NODE_ENV production

# Create a directory to use for building
RUN mkdir /app
# Set the build-directory as the working (and current) directory
WORKDIR /app

# We start by building only dependencies, this means that we can use cached dependencies
# if these files are not changed
COPY package.json .
# We are using yarn. If you use npm, this would be package-lock.json
COPY yarn.lock .
# Remove this if you are not using typescript. (but you should use typescript)
COPY tsconfig.json .
# Install dependencies
RUN yarn install --pure-lockfile

# Copy the actual code and public (static files)
COPY src src
COPY public public
# Build the dependencies. This will output to `/app/build` the static files which need to be served
# to the user
RUN yarn build


# We don't need the node-container in production, we just need something that can serve the static
# files to the user. Nginx is really good at this. `FROM` starts a new container
FROM nginx:1.15.12-alpine

# We copy the built files from the build-container. These files are in `/app/build` after the
# build-step above.
COPY --from=build /app/build /usr/share/nginx/html

iterapp.toml

readiness_path = "/"