Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Dockerfile_WebUI
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
15 changes: 15 additions & 0 deletions WebUI/docker/40-openas2-config.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
window.__OPENAS2_CONFIG__ = { restApiUrl: "${escaped}" };
EOF

echo "openas2-webui: REST API URL set to ${OPENAS2_RESTAPI_URL}"
5 changes: 5 additions & 0 deletions WebUI/public/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Runtime configuration, loaded before the app bundle.
// In a container this file is regenerated at startup by
// docker-entrypoint.d/40-openas2-config.sh from OPENAS2_RESTAPI_URL.
// An empty value falls through to the build-time default.
window.__OPENAS2_CONFIG__ = { restApiUrl: "" };
1 change: 1 addition & 0 deletions WebUI/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<strong>We're sorry but openas2ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<script src="<%= BASE_URL %>config.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.8/umd/popper.min.js" integrity="sha512-TPh2Oxlg1zp+kz3nFA0C5vVC6leG/6mm1z9+mA81MI5eaUVqasPLO8Cuk4gMF4gUfP5etR73rgU/8PNMsSesoQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.min.js" integrity="sha512-ykZ1QQr0Jy/4ZkvKuqWn4iF3lqPZyij9iRv6sGqLRdTPkY69YX6+7wvVGmsdBbiIfN/8OdsI7HABjvEok6ZopQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Expand Down
6 changes: 5 additions & 1 deletion WebUI/src/components/LoginScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading