35 lines
714 B
Bash
35 lines
714 B
Bash
#!/bin/sh
|
|||
|
|
|
||
|
|
load_env_file() {
|
||
|
|
file="$1"
|
||
|
|
[ -f "$file" ] || return 0
|
||
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
||
|
|
case "$line" in
|
||
|
|
''|\#*) continue ;;
|
||
|
|
esac
|
||
|
|
key="${line%%=*}"
|
||
|
|
val="${line#*=}"
|
||
|
|
eval "current=\${$key-}"
|
||
|
|
if [ -z "$current" ]; then
|
||
|
|
export "$key=$val"
|
||
|
|
fi
|
||
|
|
done < "$file"
|
||
|
|
}
|
||
|
|
|
||
|
|
load_env_file /app/.env.production
|
||
|
|
load_env_file /app/.env
|
||
|
|
|
||
|
|
escape_sed() {
|
||
|
|
printf '%s\n' "$1" | sed -e 's/[\/&]/\\&/g' -e 's/\./\\\./g'
|
||
|
|
}
|
||
|
|
|
||
|
|
ESCAPED_API_BASE_URL=$(escape_sed "$VITE_API_BASE_URL")
|
||
|
|
|
||
|
|
if [ -d /app/dist ]; then
|
||
|
|
find /app/dist -type f \( -name "*.js" -o -name "*.html" \) -exec sed -i \
|
||
|
|
-e "s/__VITE_API_BASE_URL__/${ESCAPED_API_BASE_URL}/g" \
|
||
|
|
{} \;
|
||
|
|
fi
|
||
|
|
|
||
|
|
exec "$@"
|