diff --git a/.env b/.env index a1d48fe..2e973a0 100644 --- a/.env +++ b/.env @@ -30,4 +30,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/Dockerfile b/Dockerfile index 090370e..2f2034d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY package*.json ./ RUN npm install COPY . ./ RUN rm .env -RUN CI=false npm run build +RUN CI=false VITE_DYNAMIC_BASE_URL=1 npm run build FROM nginx:alpine AS prod RUN apk add --no-cache bash diff --git a/docker_entrypoint.sh b/docker_entrypoint.sh index 105ae4e..e77dff3 100644 --- a/docker_entrypoint.sh +++ b/docker_entrypoint.sh @@ -1,5 +1,6 @@ #!/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 @@ -13,4 +14,12 @@ 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 + sed -i "s|/@BASE_URL@/|$VITE_BASE_URL|g" /app/index.html ${INDEX_FILE} + 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 b67725c..bcc10e8 100644 --- a/env.d.ts +++ b/env.d.ts @@ -6,6 +6,7 @@ interface ImportMetaEnv { readonly VITE_PER_PAGE: number; readonly VITE_CONCEPT_PER_PAGE: number; 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..c85af77 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,9 @@