my-recipes/frontend/10-generate-env.sh
2025-12-05 16:37:38 +02:00

24 lines
545 B
Bash

#!/bin/sh
set -e
TEMPLATE="/etc/env/env.js.template"
TARGET="/usr/share/nginx/html/env.js"
if [ -f "$TEMPLATE" ]; then
echo "Generating env.js from template with API_BASE=${API_BASE:-/api}"
# Default API_BASE to /api if not provided
: ${API_BASE:=/api}
cat > "$TARGET" <<EOF
window.__ENV__ = {
API_BASE: "${API_BASE}"
};
EOF
echo "✓ env.js generated at $TARGET"
else
echo "No env.js.template found at $TEMPLATE, skipping generation"
fi
# Ensure ownership/permissions are OK
chown -R nginx:nginx /usr/share/nginx/html || true