├── .env.sample ├── config.js.template ├── docker-compose.yml ├── config_check.sh ├── Dockerfile ├── index.html ├── LICENSE ├── error.html ├── README.md └── nginx.conf /.env.sample: -------------------------------------------------------------------------------- 1 | # Sample set of env vars 2 | CONTEXT=production 3 | ID=appId 4 | URL=http://localhost 5 | COMPONENTS=e30= 6 | -------------------------------------------------------------------------------- /config.js.template: -------------------------------------------------------------------------------- 1 | // Dynamic configuration 2 | window.__config__ = { 3 | CONTEXT: '${CONTEXT}', 4 | ID: '${ID}', 5 | URL: '${URL}', 6 | COMPONENTS: '${COMPONENTS}' 7 | } 8 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # Run with docker-compose up to test the custom nginx image 2 | 3 | version: "3.9" 4 | services: 5 | nginx: 6 | build: . 7 | env_file: .env.sample 8 | ports: 9 | - "80:80" 10 | -------------------------------------------------------------------------------- /config_check.sh: -------------------------------------------------------------------------------- 1 | # This script checks whether the essential environment variables are set 2 | 3 | echo "Checking config..." 4 | 5 | : ${CONTEXT?"CONTEXT variable is not set"} 6 | : ${ID?"ID variable is not set"} 7 | : ${URL?"URL variable is not set"} 8 | : ${COMPONENTS?"COMPONENTS variable is not set"} 9 | 10 | echo "All environment variables set" 11 | exit 0 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:alpine 2 | 3 | # Run config check script on the container startup 4 | COPY config_check.sh /docker-entrypoint.d/ 5 | # Provide improved nginx configuration 6 | COPY nginx.conf /etc/nginx/ 7 | # Fill in default server content 8 | COPY index.html error.html config.js.template /usr/share/nginx/html/ 9 | 10 | # Make env var substitution happen on *.template files in the html dir 11 | ENV NGINX_ENVSUBST_TEMPLATE_DIR=/usr/share/nginx/html 12 | ENV NGINX_ENVSUBST_OUTPUT_DIR=/usr/share/nginx/html 13 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Assembly Line 7 | 8 | 9 | 10 | 24 | 25 |

Welcome to custom nginx app server!

26 |

If you see this page, you forgot to replace the default index.html file within the nginx image with the application one.

27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Karel Klíma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <!--# echo var="status" default="" --> <!--# echo var="status_text" default="Something goes wrong" --> 7 | | Assembly Line 8 | 9 | 10 | 11 | 12 | 13 | 14 | 27 | 28 | 29 |

We are updating our website

30 |

This is only for a few seconds, you will be redirected.

31 | 32 |

33 | 34 | 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-nginx 2 | 3 | This repository contains a custom nginx server to be used for front end apps within the Assembly Line. 4 | 5 | The server is available as a Docker image. 6 | 7 | ## Motivation 8 | 9 | There are multiple front end components within the Assembly Line that need to be dockerized. Since there are a lot of commonalities, it makes sense to package them into a single Docker image rather than let all the front end apps repeat themselves. 10 | 11 | ## Features 12 | 13 | - PushState compatible (i.e. no need for hashes `#` within URL) 14 | - Checks for configuration variables on Docker startup 15 | - Creates `config.js` file containing the configuration variables 16 | 17 | ## Usage 18 | 19 | Sample Dockerfile for your React app 20 | 21 | ``` 22 | # Build stage 23 | FROM node:alpine 24 | 25 | ARG PUBLIC_PATH=/ 26 | 27 | # Make sure that React app is built using the right path context 28 | ENV PUBLIC_URL=${PUBLIC_PATH} 29 | 30 | WORKDIR /usr/src/app 31 | COPY . ./ 32 | 33 | RUN set -ex; \ 34 | npm install; \ 35 | npm run build 36 | 37 | # Run stage 38 | FROM #TODO: replace with right package name 39 | WORKDIR /usr/share/nginx/html 40 | #COPY --from=0 /usr/src/app/build/ ./ 41 | #COPY --from=0 /usr/src/app/public/*.template ./ 42 | ``` 43 | 44 | Add the following to the 45 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 1; 2 | 3 | events { 4 | worker_connections 1024; 5 | } 6 | 7 | http { 8 | 9 | map $status $status_text { 10 | 400 'Bad Request'; 11 | 401 'Unauthorized'; 12 | 403 'Forbidden'; 13 | 404 'Not Found'; 14 | 405 'Method Not Allowed'; 15 | 406 'Not Acceptable'; 16 | 413 'Payload Too Large'; 17 | 414 'URI Too Long'; 18 | 431 'Request Header Fields Too Large'; 19 | 500 'Internal Server Error'; 20 | 501 'Not Implemented'; 21 | 502 'Bad Gateway'; 22 | 503 'Service Unavailable'; 23 | 504 'Gateway Timeout'; 24 | } 25 | 26 | server { 27 | listen 80; 28 | server_name localhost; 29 | 30 | error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 31 | 415 416 417 418 421 422 423 424 426 428 429 431 451 500 501 502 503 32 | 504 505 506 507 508 510 511 /error.html; 33 | 34 | location = /error.html { 35 | ssi on; 36 | internal; 37 | root /usr/share/nginx/html; 38 | } 39 | 40 | location / { 41 | root /usr/share/nginx/html; 42 | index index.html index.htm; 43 | try_files $uri $uri/ /index.html =404; 44 | } 45 | 46 | 47 | } 48 | } --------------------------------------------------------------------------------