diff --git a/CHANGELOG.md b/CHANGELOG.md index 8634b37e..ccb80f6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v3.2.2 +### Feat +- add subpath/base url for frontend + ## v3.2.1 ### Fix - change status from wildcard to exact match in alert and history filter diff --git a/Dockerfile b/Dockerfile index 24c77dcb..9dc6e1c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ ENV UWSGI_LISTEN=100 ENV UWSGI_BUFFER_SIZE=8192 ENV UWSGI_MAX_WORKER_LIFETIME=30 ENV UWSGI_WORKER_LIFETIME_DELTA=3 +ENV FRONTEND_BASE_URL=/ ENV HEARTBEAT_SEVERITY=major diff --git a/config/templates/app/alerta.conf.j2 b/config/templates/app/alerta.conf.j2 index 94a33d26..d4b5494e 100644 --- a/config/templates/app/alerta.conf.j2 +++ b/config/templates/app/alerta.conf.j2 @@ -1,7 +1,7 @@ [DEFAULT] sslverify = no output = presto -endpoint = http://localhost:8080/api +endpoint = http://localhost:8080{{ env.FRONTEND_BASE_URL }}api timezone = Europe/London {%- if env.API_KEY %} key = {{ env.API_KEY }} diff --git a/config/templates/app/nginx.conf.j2 b/config/templates/app/nginx.conf.j2 index 76772ab7..00bd6a65 100644 --- a/config/templates/app/nginx.conf.j2 +++ b/config/templates/app/nginx.conf.j2 @@ -46,7 +46,7 @@ http { access_log /dev/stdout main; - location /api { + location {{ env.FRONTEND_BASE_URL }}api { include /etc/nginx/uwsgi_params; uwsgi_pass backend; @@ -58,8 +58,9 @@ http { root /web; index index.html; - location / { - try_files $uri $uri/ /index.html; + + location {{ env.FRONTEND_BASE_URL }} { + try_files $uri $uri/ {{ env.FRONTEND_BASE_URL }}index.html; } } } diff --git a/config/templates/app/uwsgi.ini.j2 b/config/templates/app/uwsgi.ini.j2 index e345b52c..2c9c11ed 100644 --- a/config/templates/app/uwsgi.ini.j2 +++ b/config/templates/app/uwsgi.ini.j2 @@ -4,7 +4,7 @@ log-route = info ^\D chdir = /app module = wsgi manage-script-name = true -mount = /api=wsgi:app +mount = {{ env.FRONTEND_BASE_URL }}api=wsgi:app master = true processes = {{ env.UWSGI_PROCESSES }} listen = {{ env.UWSGI_LISTEN }} diff --git a/config/templates/web/config.json.j2 b/config/templates/web/config.json.j2 index 004ae8e0..cc9cd328 100644 --- a/config/templates/web/config.json.j2 +++ b/config/templates/web/config.json.j2 @@ -1 +1,4 @@ -{"endpoint": "/api"} +{ + "endpoint": "{{ env.FRONTEND_BASE_URL }}api", + "base": "{{ env.FRONTEND_BASE_URL }}" +} diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5a188b39..2b9b56fe 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,7 +4,7 @@ JINJA2="import os, sys, jinja2; sys.stdout.write(jinja2.Template(sys.stdin.read( ALERTA_CONF_FILE=${ALERTA_CONF_FILE:-/app/alerta.conf} ALERTA_SVR_CONF_FILE=${ALERTA_SVR_CONF_FILE:-/app/alertad.conf} -ALERTA_WEB_CONF_FILE=${ALERTA_WEB_CONF_FILE:-/web/config.json} +ALERTA_WEB_CONF_FILE=/web${FRONTEND_BASE_URL}config.json NGINX_CONF_FILE=/app/nginx.conf UWSGI_CONF_FILE=/app/uwsgi.ini SUPERVISORD_CONF_FILE=/app/supervisord.conf @@ -76,6 +76,11 @@ if [ ! -f "${UWSGI_CONF_FILE}" ]; then python3 -c "${JINJA2}" < ${UWSGI_CONF_FILE}.j2 >${UWSGI_CONF_FILE} fi +if [ ! -d "/web${FRONTEND_BASE_URL}" ]; then + mkdir /web${FRONTEND_BASE_URL} + mv /web/* /web${FRONTEND_BASE_URL} || : +fi + # Generate web config, if not supplied. if [ ! -f "${ALERTA_WEB_CONF_FILE}" ]; then if [ $INIT_LOG = true ]; then echo "# Create web configuration file."; fi