Files
faunosteo/docker/entrypoint.sh
T
Bastien Chanot 0214ae1537 fix(docker): escape env values in env.js heredoc
SEC-9: a double quote or backslash in APP_* broke the generated JS
(silent config corruption). js_escape() escapes both and collapses
newlines before interpolation. Docker-verified with a hostile
APP_BRAND_NAME: env.js parses, value round-trips exactly.
2026-07-12 16:26:21 +02:00

39 lines
1.2 KiB
Bash

#!/bin/sh
# Injects runtime env vars into /usr/share/nginx/html/env.js
# which is loaded by index.html before the React bundle.
# Values come from Docker env vars (set via env_file in docker-compose.yml).
set -e
ENV_JS="/usr/share/nginx/html/env.js"
# Escapes a value for safe embedding in a double-quoted JS string literal
# (backslashes, double quotes; newlines collapsed to spaces).
js_escape() {
printf '%s' "$1" | tr '\n' ' ' | sed 's/\\/\\\\/g; s/"/\\"/g'
}
SITE_NAME=$(js_escape "${APP_SITE_NAME:-Faunosteo}")
BRAND_NAME=$(js_escape "${APP_BRAND_NAME:-Faunosteo}")
FOOTER_NAME=$(js_escape "${APP_FOOTER_NAME:-Faunosteo}")
TAGLINE=$(js_escape "${APP_TAGLINE:-Outils pour ostéopathes animaliers}")
cat > "$ENV_JS" <<EOF
window.__APP_CONFIG__ = {
siteName: "${SITE_NAME}",
brandName: "${BRAND_NAME}",
footerName: "${FOOTER_NAME}",
tagline: "${TAGLINE}"
};
EOF
echo "env.js written: APP_BRAND_NAME=${APP_BRAND_NAME:-Faunosteo}"
# Replace PORT placeholder in nginx config if needed
# (nginx:alpine supports envsubst via templates; we keep it explicit)
export PORT="${PORT:-8080}"
envsubst '${PORT}' < /etc/nginx/conf.d/default.conf > /tmp/nginx_default.conf
cp /tmp/nginx_default.conf /etc/nginx/conf.d/default.conf
exec nginx -g "daemon off;"