Files
wyndham-Condon/deploy/frontend-entrypoint.sh
2026-08-03 11:25:55 +08:00

35 lines
835 B
Bash

#!/bin/sh
set -eu
runtime_config_path="/usr/share/nginx/html/runtime-config.js"
default_mode="${CONDO_DEFAULT_MODE:-api}"
api_base_url="${CONDO_API_BASE_URL:-/api}"
period_year="${CONDO_PERIOD_YEAR:-}"
escape_js_string() {
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}
case "$period_year" in
"" )
period_year_expression="new Date().getUTCFullYear()"
;;
*[!0-9]* )
period_year_expression="new Date().getUTCFullYear()"
;;
* )
period_year_expression="$period_year"
;;
esac
default_mode_escaped="$(escape_js_string "$default_mode")"
api_base_url_escaped="$(escape_js_string "$api_base_url")"
cat > "$runtime_config_path" <<EOF
window.CONDO_RUNTIME_CONFIG = Object.freeze({
defaultMode: "$default_mode_escaped",
apiBaseUrl: "$api_base_url_escaped",
periodYear: $period_year_expression
});
EOF