#!/bin/sh # Render the runtime config from container env so a single built image serves # any deployment. Runs before nginx starts (nginx /docker-entrypoint.d hook). # # WARMBLY_CONFIG_OUT moves where it writes, which is how a static host that # has no container start renders the same file at build time. One definition # of the key set, so the two paths cannot drift apart. set -eu CONFIG_OUT="${WARMBLY_CONFIG_OUT:-/usr/share/nginx/html/config.js}" mkdir -p "$(dirname "$CONFIG_OUT")" # Values are written into JavaScript string literals, so a double quote, a # backslash or a line break in one would end the literal early and take the # whole config with it, leaving the app with no API_URL at all. Escape rather # than trust whatever ended up in .env. js() { printf '%s' "$1" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | tr -d '\r\n' } cat > "$CONFIG_OUT" <