Skip to content

Commit

Permalink
fix(frontend): fix inject gateway url into static
Browse files Browse the repository at this point in the history
DEBUG=0 was broken because gateway host was injected into the source
instead of the static assets which are built. Also, port and debug flag
was not properly injected
  • Loading branch information
jesseylin committed Jul 27, 2023
1 parent f334381 commit 63c365e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions services/base/FrontEndApp/bash/custom-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ else
GATEWAY_HOST=${GATEWAY_HOST}
fi

if [[ -z "${GATEWAY_PORT}" ]]; then
GATEWAY_PORT=4201
else
GATEWAY_PORT=${GATEWAY_PORT}
fi

# runtime injection of $GATEWAY_HOST
# TODO: probably there is something better than this
# Arguments:
Expand All @@ -20,20 +26,31 @@ fi
injectenv() {
local filename="$1"
local hostname="$2"
local port="$3"
local debug="$4"

# Replace the value of window["env"]["GATEWAY_HOST"] with ${hostname}
sed -i -e "s|\(window\[\"env\"\]\[\"GATEWAY_HOST\"\]\) = \"\(.*\)\";|\1 = \"${hostname}\";|" \
$filename

# Replace the value of window["env"]["GATEWAY_PORT"] with ${port}
sed -i -e "s|\(window\[\"env\"\]\[\"GATEWAY_PORT\"\]\) = \"\(.*\)\";|\1 = \"${port}\";|" \
$filename

# Replace the value of window["env"]["DEBUG"] with ${debug}
sed -i -e "s|\(window\[\"env\"\]\[\"debug\"\]\) = \"\(.*\)\";|\1 = \"${port}\";|" \
$filename
}

# note: please be in the right workdir before doing this
if [ $DEBUG -eq 0 ]; then
injectenv "./src/assets/env.js" ${GATEWAY_HOST}
injectenv "/usr/share/nginx/www/angular_app/assets/env.js" ${GATEWAY_HOST} ${GATEWAY_PORT} ${DEBUG}
echo "custom_entrypoint.sh: Injected gateway URL as ${GATEWAY_HOST}:${GATEWAY_PORT}"
# serve static web app
/docker-entrypoint.sh nginx -g "daemon off;"
else
injectenv "./src/assets/env.js" ${GATEWAY_HOST}
echo "custom_entrypoint.sh: Injected GATEWAY_HOST=${GATEWAY_HOST}"
injectenv "./src/assets/env.js" ${GATEWAY_HOST} ${GATEWAY_PORT} ${DEBUG}
echo "custom_entrypoint.sh: Injected gateway URL as ${GATEWAY_HOST}:${GATEWAY_PORT}"
# run angular development server
export NODE_OPTIONS=--openssl-legacy-provider
ng serve --configuration development --host 0.0.0.0 --port 80
Expand Down

0 comments on commit 63c365e

Please sign in to comment.