From c9aa68b28b78ca48f651abd9b8d6d954cc9f003c Mon Sep 17 00:00:00 2001 From: Dylan Decrulle <81740200+ddecrulle@users.noreply.github.com> Date: Thu, 20 Jan 2022 11:01:48 +0100 Subject: [PATCH] add configuration file --- .env | 1 + Dockerfile | 10 ++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 4 ++++ entrypoint.sh | 3 +++ jsconfig.json | 5 +++++ nginx.conf | 29 +++++++++++++++++++++++++++++ package.json | 9 +++++---- scripts/generate-entrypoint.js | 22 ++++++++++++++++++++++ 9 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 .env create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 entrypoint.sh create mode 100644 jsconfig.json create mode 100644 nginx.conf create mode 100644 scripts/generate-entrypoint.js diff --git a/.env b/.env new file mode 100644 index 0000000..83bf541 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +REACT_APP_LOCAL= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b3c9f07 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM nginx +COPY build /usr/share/nginx/html +RUN rm etc/nginx/conf.d/default.conf +COPY nginx.conf etc/nginx/conf.d/ + +COPY entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh + +ENTRYPOINT [ "/entrypoint.sh" ] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5273aca --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 INSEE (http://insee.fr) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index c0541f9..586ee42 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Knowledge + +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) + # Getting Started with Create React App This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2549a95 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "window._env_['LOCAL'] = '$LOCAL';" >> /usr/share/nginx/html/env-config.js +exec "$@" \ No newline at end of file diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..950a3d3 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "baseUrl": "./src" + } +} diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2ce9bd9 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80 default_server; + server_name /usr/share/nginx/html; + + root /usr/share/nginx/html; + index index.html; + + location ~* \.(?:manifest|appcache|html?|xml|json)$ { + expires -1; + # access_log logs/static.log; # I don't usually include a static log + } + + location ~* \.(?:css|js)$ { + try_files $uri =404; + expires 1y; + access_log off; + add_header Cache-Control "public"; + } + + # Any route containing a file extension (e.g. /devicesfile.js) + location ~ ^.+\..+$ { + try_files $uri =404; + } + + # Any route that doesn't have a file extension (e.g. /devices) + location / { + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6116cfe..0d75fc6 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "knowledge", "version": "0.1.0", - "private": true, - "dependencies": { + "license": "MIT", + "dependencies": { "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^12.0.0", "@testing-library/user-event": "^13.2.1", @@ -13,9 +13,10 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "npm run generate-entrypoint && react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" + "eject": "react-scripts eject", + "generate-entrypoint": "node scripts/generate-entrypoint.js" }, "eslintConfig": { "extends": [ diff --git a/scripts/generate-entrypoint.js b/scripts/generate-entrypoint.js new file mode 100644 index 0000000..55edd60 --- /dev/null +++ b/scripts/generate-entrypoint.js @@ -0,0 +1,22 @@ +var fs = require('fs'); + +fs.readFile('.env', 'utf8', function(_, contents) { + const content = contents + .split('\n') + .filter(line => !line.startsWith('#')) + .map(line => line.split('=')) + .filter(data => data.length === 2) + .map( + ([key]) => + `echo "window._env_['${key.replace( + 'REACT_APP_', + '', + )}'] = '\$${key.replace( + 'REACT_APP_', + '', + )}';" >> /usr/share/nginx/html/env-config.js`, + ); + + const fullFile = ['#!/bin/sh', ...content, 'exec "$@"'].join('\n'); + fs.writeFileSync('entrypoint.sh', fullFile, 'utf8'); +}); \ No newline at end of file