diff --git a/Dockerfile b/Dockerfile index 161510c..fa4dcd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,11 @@ RUN npm run build # production environment FROM nginx:stable-alpine +RUN apk add --no-cache jq COPY --from=build /app/dist /usr/share/nginx/html COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf +COPY docker_entrypoint.sh generate_config_js.sh / +RUN chmod +x docker_entrypoint.sh generate_config_js.sh + EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +ENTRYPOINT ["/docker_entrypoint.sh"] \ No newline at end of file diff --git a/app/config.js b/app/config.js new file mode 100644 index 0000000..368bd2a --- /dev/null +++ b/app/config.js @@ -0,0 +1 @@ +window.REACT_APP_API = undefined; diff --git a/app/index.html b/app/index.html index 98ebab8..d08ff93 100644 --- a/app/index.html +++ b/app/index.html @@ -9,6 +9,7 @@ +
diff --git a/app/index.js b/app/index.js index facf5c3..7e9a7fa 100644 --- a/app/index.js +++ b/app/index.js @@ -18,9 +18,7 @@ import { getItem, setItem, removeItem } from 'utils/localStorage'; import history from 'utils/history'; const API_URI = - process.env.NODE_ENV === 'development' - ? 'http://localhost:4000/' - : 'https://wlan-graphql.zone3.lab.connectus.ai/'; + process.env.NODE_ENV === 'development' ? 'http://localhost:4000/' : window.REACT_APP_API; const MOUNT_NODE = document.getElementById('root'); const cache = new InMemoryCache(); diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh new file mode 100644 index 0000000..a935982 --- /dev/null +++ b/docker_entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh -eu +./generate_config_js.sh >/usr/share/nginx/html/config.js +nginx -g "daemon off;" \ No newline at end of file diff --git a/generate_config_js.sh b/generate_config_js.sh new file mode 100644 index 0000000..0726061 --- /dev/null +++ b/generate_config_js.sh @@ -0,0 +1,10 @@ +#!/bin/sh -eu +if [ -z "${API:-}" ]; then + API_URL_JSON=undefined +else + API_URL_JSON=$(jq -n --arg api '$API' '$api') +fi + +cat <