generated from nholtware/service-template-react
Initial commit
This commit is contained in:
commit
3a8e7184d5
32 changed files with 5218 additions and 0 deletions
26
docker-entrypoint.d/10-config.sh
Executable file
26
docker-entrypoint.d/10-config.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/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"
|
||||
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"
|
||||
echo "10-config.sh: wrote $OUT"
|
||||
Loading…
Add table
Add a link
Reference in a new issue