diff options
| -rw-r--r-- | Dockerfile | 4 | ||||
| -rwxr-xr-x | nginx-entrypoint.sh | 23 | ||||
| -rw-r--r-- | rollup.config.js | 2 | ||||
| -rw-r--r-- | src/inject.template.js | 4 |
4 files changed, 12 insertions, 21 deletions
@@ -11,8 +11,8 @@ RUN npm run build FROM nginx:alpine AS server WORKDIR /usr/share/nginx/html -RUN apk add --no-cache bash +RUN apk add --no-cache gettext COPY nginx-entrypoint.sh / COPY --from=builder /app/dist ./ -ENTRYPOINT [ "bash", "/nginx-entrypoint.sh" ] +ENTRYPOINT [ "sh", "/nginx-entrypoint.sh" ] diff --git a/nginx-entrypoint.sh b/nginx-entrypoint.sh index e6ed329..6518f10 100755 --- a/nginx-entrypoint.sh +++ b/nginx-entrypoint.sh @@ -1,22 +1,9 @@ -#!/usr/bin/bash +#!/bin/sh WWW_DIR=/usr/share/nginx/html -ENV_PREFIX=FRONTEND_ -INJECT_FILE_PATH="${WWW_DIR}/inject.js" +INJECT_FILE_SRC="${WWW_DIR}/inject.template.js" +INJECT_FILE_DST="${WWW_DIR}/inject.js" -cat >> "${INJECT_FILE_PATH}" << EOF -window.injectedEnv = { - NODE_ENV: "production", -EOF +envsubst < "${INJECT_FILE_SRC}" > "${INJECT_FILE_DST}" -for envrow in $(printenv); do - IFS='=' read -r key value <<< "${envrow}" - - if [[ $key == "${ENV_PREFIX}"* ]]; then - echo " ${key}: \"${value}\"," >> "${INJECT_FILE_PATH}" - fi -done - -echo "};" >> "${INJECT_FILE_PATH}" - -[ -z "$@" ] && nginx -g 'daemon off;' || "$@" +[ -z "$@" ] && nginx -g 'daemon off;' || $@ diff --git a/rollup.config.js b/rollup.config.js index 56fd795..8460edf 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -12,7 +12,7 @@ export default { plugins: [ resolve(), copy({ - targets: [ { src: 'src/index.html', dest: 'dist/' } ], + targets: [ { src: 'src/index.html', dest: 'dist/' }, { src: 'src/inject.template.js', dest: 'dist/' } ], }), ], }; diff --git a/src/inject.template.js b/src/inject.template.js new file mode 100644 index 0000000..cd928bb --- /dev/null +++ b/src/inject.template.js @@ -0,0 +1,4 @@ +window.injectedEnv = { + NODE_ENV: '${NODE_ENV}', + FRONTEND_EXAMPLE_ENV: '${FRONTEND_EXAMPLE_ENV}', +}; |
