Remove env-config.js (#9331)

Fixes #5340 which had been open for a long time
This commit is contained in:
Félix Malfait
2025-01-03 15:18:02 +01:00
committed by GitHub
parent 03b1da82c1
commit e5754d2152
7 changed files with 54 additions and 32 deletions

View File

@ -1,12 +1,25 @@
#!/bin/sh
echo "Generating env-config.js file from runtime environment variables..."
BASE_FILENAME="build/env-config.js"
mkdir -p build
rm -rf "./$BASE_FILENAME"
echo "Injecting runtime environment variables into index.html..."
{
echo "window._env_ = {"
echo " REACT_APP_SERVER_BASE_URL: \"$REACT_APP_SERVER_BASE_URL\","
echo "}"
} > "./$BASE_FILENAME"
CONFIG_BLOCK=$(cat << EOF
<script id="twenty-env-config">
window._env_ = {
REACT_APP_SERVER_BASE_URL: "$REACT_APP_SERVER_BASE_URL"
};
</script>
<!-- END: Twenty Config -->
EOF
)
# Use sed to replace the config block in index.html
# Using pattern space to match across multiple lines
sed -i.bak '
/<!-- BEGIN: Twenty Config -->/,/<!-- END: Twenty Config -->/{
/<!-- BEGIN: Twenty Config -->/!{
/<!-- END: Twenty Config -->/!d
}
/<!-- BEGIN: Twenty Config -->/r /dev/stdin
/<!-- END: Twenty Config -->/d
}
' build/index.html <<< "$CONFIG_BLOCK"
rm -f build/index.html.bak