From 378c1ef1c092c669ade2755156dbc27f869bdee1 Mon Sep 17 00:00:00 2001 From: jamiefeiss Date: Fri, 21 Apr 2023 16:39:23 +1000 Subject: [PATCH 1/3] Added configuring base URL from env var for both static site & docker --- .env | 2 +- docker_entrypoint.sh | 9 ++++++- env.d.ts | 1 + index.html | 40 +++++++++++++++++++++++---- vite.config.ts | 64 +++++++++++++++++++++++--------------------- 5 files changed, 79 insertions(+), 37 deletions(-) diff --git a/.env b/.env index 8a4566f..48dad1a 100644 --- a/.env +++ b/.env @@ -27,4 +27,4 @@ VITE_MAP_SEARCH_PROPS_DS_LABEL=http://purl.org/dc/terms/title ## LOCAL DEV ENVIRONMENT ## --------------------------------------- VITE_API_BASE_URL=http://localhost:8000 - +VITE_BASE_URL=/ diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index bef4085..93b58b5 100644 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash +# insert env vars in index.js INDEX_FILE=/app/assets/index.*.js; - grep "=" .env | while read -r line; do # loop over VITE_ env vars left=`echo $line | awk -F "=" '{print $1}'`; # env var name right=`echo $line | awk -F "=" '{print $2}'`; # default value @@ -13,4 +13,11 @@ grep "=" .env | while read -r line; do # loop over VITE_ env vars fi done +# insert base url in index.html +if (declare -p "VITE_BASE_URL" &>/dev/null) +then + sed -i "s|BASE_URL = \"/\"|BASE_URL = \"$VITE_BASE_URL\"|g" /app/index.html + cp /app/index.html /app/404.html +fi + nginx -g 'daemon off;'; \ No newline at end of file diff --git a/env.d.ts b/env.d.ts index b10c65f..17fc3eb 100644 --- a/env.d.ts +++ b/env.d.ts @@ -3,6 +3,7 @@ interface ImportMetaEnv { readonly VITE_SIDENAV: string; // true | false readonly VITE_ENABLED_PREZS: string; // CatPrez | SpacePrez | VocPrez comma separated readonly VITE_API_BASE_URL: string; + readonly VITE_BASE_URL: string; readonly VITE_MAP_SETTINGS_API_KEY: string; readonly VITE_MAP_SETTINGS_OPTIONS_CENTER_LAT: number; readonly VITE_MAP_SETTINGS_OPTIONS_CENTER_LNG: number; diff --git a/index.html b/index.html index ad7ead7..f4a4a29 100644 --- a/index.html +++ b/index.html @@ -6,8 +6,8 @@ Prez - - + + @@ -17,7 +17,38 @@