Patrick Lee Scott
1 min readMar 27, 2019

--

Another option: Build with dummy values like “REPLACE_API_URL” and then use an entrypoint.sh to replace them with sed on startup:

#!/bin/bashecho "Inserting env variables"for file in ./build/static/js/*.js
do
echo "env sub for $file"
list="$(cat /proc/self/environ | awk -F= '{print $1}')"
echo "$list" | while read -r line; do
export REPLACE="REPLACE_$line"
export VALUE=$(eval "echo \"\$$line\"")
# for debugging use (DO NOT ENABLE IN PRODUCTION):
# echo "replacing ${REPLACE} with ${VALUE} in $file"
sed -i "s~${REPLACE}~${VALUE}~g" $file
unset REPLACE
unset VALUE
done
done
node scripts/server.js

This script even works on Alpine, which was a special challenge in itself :)

--

--

Patrick Lee Scott
Patrick Lee Scott

Written by Patrick Lee Scott

I make things for the internet, that scale, look nice, and make money!

Responses (2)