diff --git a/nextjs-base/scripts/apply-runtime-env.sh b/nextjs-base/scripts/apply-runtime-env.sh index 242b948..e703a01 100755 --- a/nextjs-base/scripts/apply-runtime-env.sh +++ b/nextjs-base/scripts/apply-runtime-env.sh @@ -38,7 +38,9 @@ if [ -f ".env" ]; then fi for f in $(find . -type f \( -regex '.*.html?' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do - for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();]' '\n' | tr -s "[']" '\n' | egrep -o -e '^STACK_RUNTIME_ENV_.+$' -e '^STACK_HOSTED_CONFIG_.+$'); do + # Backticks are delimiters too: esbuild-based bundlers (vite) will happily emit + # a placeholder as a template literal, e.g. var a=`STACK_RUNTIME_ENV_API_URL`. + for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();`]' '\n' | tr -s "[']" '\n' | egrep -o -e '^STACK_RUNTIME_ENV_.+$' -e '^STACK_HOSTED_CONFIG_.+$'); do orig_name=$(echo -n "${e}" | sed 's/"//g') cur_name=$(echo -n "${orig_name}" | sed 's/STACK_RUNTIME_ENV_//g') cur_val=$(echo -n "\$${cur_name}" | envsubst) diff --git a/webapp-base/scripts/apply-runtime-env.sh b/webapp-base/scripts/apply-runtime-env.sh index 25363b3..80294dc 100755 --- a/webapp-base/scripts/apply-runtime-env.sh +++ b/webapp-base/scripts/apply-runtime-env.sh @@ -21,7 +21,9 @@ if [ -f ".env" ]; then fi for f in $(find . -type f \( -regex '.*.html?' -or -regex ".*.[tj]s\(x\|on\)?$" \) | grep -v 'node_modules' | grep -v '.git'); do - for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();]' '\n' | tr -s "[']" '\n' | egrep -o -e '^STACK_RUNTIME_ENV_.+$' -e '^STACK_HOSTED_CONFIG_.+$'); do + # Backticks are delimiters too: esbuild-based bundlers (vite) will happily emit + # a placeholder as a template literal, e.g. var a=`STACK_RUNTIME_ENV_API_URL`. + for e in $(cat "${f}" | tr -s '[:blank:]' '\n' | tr -s '["/\\{},();`]' '\n' | tr -s "[']" '\n' | egrep -o -e '^STACK_RUNTIME_ENV_.+$' -e '^STACK_HOSTED_CONFIG_.+$'); do orig_name=$(echo -n "${e}" | sed 's/"//g') cur_name=$(echo -n "${orig_name}" | sed 's/STACK_RUNTIME_ENV_//g') cur_val=$(echo -n "\$${cur_name}" | envsubst)