my-recipes/frontend/10-generate-env.sh

33 lines
833 B
Bash

#!/bin/sh
set -e
# Template is in dist (copied by Dockerfile builder stage)
TEMPLATE="/usr/share/nginx/html/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 "Warning: env.js.template not found at $TEMPLATE, creating default env.js"
# Fallback: create env.js with default value
: ${API_BASE:=/api}
cat > "$TARGET" <<EOF
window.__ENV__ = {
API_BASE: "${API_BASE}"
};
EOF
echo "✓ Default env.js created at $TARGET"
fi
# Ensure ownership/permissions are OK for nginx
chown -R nginx:nginx /usr/share/nginx/html || true