From d14a57a729274c741047b635dfc865dbd094915b Mon Sep 17 00:00:00 2001 From: Javier Munoz Date: Thu, 6 Aug 2026 10:00:34 -0400 Subject: [PATCH] fix(webui): read REST API URL at runtime instead of build time The API URL was inlined into the JS bundle by Vue CLI, so a published image only ever worked against whatever host it was built for. Serve the value from config.js instead, regenerated at container start from OPENAS2_RESTAPI_URL (default http://localhost:8443/api) by a script in nginx's /docker-entrypoint.d. One image now serves any deployment. The build-time VUE_APP_RESTAPI_URL still works as a fallback, so existing builds are unaffected. --- Dockerfile_WebUI | 6 +++++- WebUI/docker/40-openas2-config.sh | 15 +++++++++++++++ WebUI/public/config.js | 5 +++++ WebUI/public/index.html | 1 + WebUI/src/components/LoginScreen.vue | 6 +++++- docker-compose.yml | 4 ++-- 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 WebUI/docker/40-openas2-config.sh create mode 100644 WebUI/public/config.js diff --git a/Dockerfile_WebUI b/Dockerfile_WebUI index 87f7fd069..ac48acb80 100644 --- a/Dockerfile_WebUI +++ b/Dockerfile_WebUI @@ -9,4 +9,8 @@ ENV VUE_APP_RESTAPI_URL=${VUE_APP_RESTAPI_URL:-http://localhost:8080} RUN yarn run build FROM nginx:stable-alpine -COPY --from=web-builder /usr/src/webui/dist /usr/share/nginx/html \ No newline at end of file +COPY --from=web-builder /usr/src/webui/dist /usr/share/nginx/html +# Set at container start, not build time, so one image serves any deployment. +ENV OPENAS2_RESTAPI_URL=http://localhost:8443/api +COPY ./WebUI/docker/40-openas2-config.sh /docker-entrypoint.d/40-openas2-config.sh +RUN chmod +x /docker-entrypoint.d/40-openas2-config.sh \ No newline at end of file diff --git a/WebUI/docker/40-openas2-config.sh b/WebUI/docker/40-openas2-config.sh new file mode 100644 index 000000000..e0550cb67 --- /dev/null +++ b/WebUI/docker/40-openas2-config.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Regenerate the runtime config the WebUI reads before booting. +# Runs automatically: nginx's entrypoint sources /docker-entrypoint.d/*.sh. +set -e + +: "${OPENAS2_RESTAPI_URL:=http://localhost:8443/api}" + +# Escape backslashes and double quotes so the URL is a safe JS string literal. +escaped=$(printf '%s' "$OPENAS2_RESTAPI_URL" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g') + +cat > /usr/share/nginx/html/config.js <We're sorry but openas2ui doesn't work properly without JavaScript enabled. Please enable it to continue.
+ diff --git a/WebUI/src/components/LoginScreen.vue b/WebUI/src/components/LoginScreen.vue index cff12e26d..4f1584362 100644 --- a/WebUI/src/components/LoginScreen.vue +++ b/WebUI/src/components/LoginScreen.vue @@ -37,7 +37,11 @@ export default { data: function() {return { username: '', password: '', - server: process.env.VUE_APP_RESTAPI_URL || 'http://127.0.0.1:8443/api', + // Runtime config (config.js) wins so one image can serve any deployment, + // then the build-time value, then a local dev default. + server: (window.__OPENAS2_CONFIG__ && window.__OPENAS2_CONFIG__.restApiUrl) + || process.env.VUE_APP_RESTAPI_URL + || 'http://127.0.0.1:8443/api', rememberme: false, loading: false, errormsg: '', diff --git a/docker-compose.yml b/docker-compose.yml index a98c977df..8b3d3473b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,8 +23,8 @@ services: build: context: . dockerfile: Dockerfile_WebUI - args: - - VUE_APP_RESTAPI_URL=http://localhost:${HOST_RESTAPI_PORT:-8443}/api + environment: + - OPENAS2_RESTAPI_URL=http://localhost:${HOST_RESTAPI_PORT:-8443}/api ports: - ${HOST_WEBUI_PORT:-8080}:80 tty: true