This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# Vite inlines import.meta.env.VITE_* at build time, so runtime configuration cannot
|
||||
# come from an env var the app reads directly. Instead we write /config.js here, which
|
||||
# src/app.html loads synchronously ahead of the bundle. One image, any environment.
|
||||
set -eu
|
||||
|
||||
config_file=/usr/share/nginx/html/config.js
|
||||
|
||||
# Drop control characters (newlines included) so the value cannot break out of the
|
||||
# string literal, then escape backslashes before double quotes. A URL containing
|
||||
# & ? " or a trailing slash stays inert data.
|
||||
value=$(printf '%s' "${LADOSE_API_BASE_URL:-}" | tr -d '\001-\037')
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
# Empty object, not an empty string: lets the app keep its baked-in default.
|
||||
printf 'window.__LADOSE_CONFIG__ = {};\n' >"$config_file"
|
||||
echo "config.js: LADOSE_API_BASE_URL unset, deferring to the built-in default" >&2
|
||||
else
|
||||
escaped=$(printf '%s' "$value" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||
printf 'window.__LADOSE_CONFIG__ = { apiBaseUrl: "%s" };\n' "$escaped" >"$config_file"
|
||||
echo "config.js: apiBaseUrl=$value" >&2
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user