#!/bin/sh
set -e

# Replace placeholders in env.template.js with environment variables and write env.js
TEMPLATE_PATH="/usr/share/nginx/html/env.template.js"
TARGET_PATH="/usr/share/nginx/html/env.js"

if [ -f "$TEMPLATE_PATH" ]; then
  echo "Rendering runtime config from $TEMPLATE_PATH"
  echo "Using environment variables:"
  printenv
  echo "----"
  envsubst < "$TEMPLATE_PATH" > "$TARGET_PATH"
else
  echo "No runtime template found at $TEMPLATE_PATH, skipping"
fi

exec nginx -g 'daemon off;'
