generated from nholtware/service-template-react
Initial commit
This commit is contained in:
commit
69da1d8f34
34 changed files with 5531 additions and 0 deletions
34
docker-entrypoint.d/10-config.sh
Executable file
34
docker-entrypoint.d/10-config.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
# Run by the nginx image's entrypoint before nginx starts. Writes the runtime
|
||||
# config the SPA reads as window.__APP_CONFIG__, so one image serves every
|
||||
# environment. To expose a new env var to the browser, add its name to VARS.
|
||||
# Never put secrets here: everything in config.js is public.
|
||||
set -eu
|
||||
|
||||
VARS="API_BASE_URL APP_NAME UNLEASH_URL UNLEASH_FRONTEND_TOKEN"
|
||||
OUT=/usr/share/nginx/html/config.js
|
||||
|
||||
: "${API_BASE_URL:=/api}"
|
||||
: "${APP_NAME:=app}"
|
||||
|
||||
json_escape() {
|
||||
printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
|
||||
}
|
||||
|
||||
body=""
|
||||
for name in $VARS; do
|
||||
eval "value=\${$name:-}"
|
||||
[ -n "$body" ] && body="$body,"
|
||||
body="$body\"$name\":\"$(json_escape "$value")\""
|
||||
done
|
||||
|
||||
printf 'window.__APP_CONFIG__ = {%s};\n' "$body" > "$OUT"
|
||||
|
||||
# nginx variables for the JSON access log (nginx/default.conf). Restricted
|
||||
# charset: these land inside nginx string literals.
|
||||
safe() { printf '%s' "$1" | tr -cd 'A-Za-z0-9._-'; }
|
||||
cat > /etc/nginx/conf.d/service-vars.conf <<NGINX
|
||||
map \$host \$app_name { default "$(safe "$APP_NAME")"; }
|
||||
map \$host \$git_sha { default "$(safe "${GIT_SHA:-dev}")"; }
|
||||
NGINX
|
||||
echo "10-config.sh: wrote $OUT and service-vars.conf"
|
||||
Loading…
Add table
Add a link
Reference in a new issue