docker-alerta: config.json does not respect base_url

Issue Summary When setting BASE_URL to e.g. /alerta, config.json still gets loaded from /

Environment

  • OS: Linux

  • API version: 7.4.0

  • Deployment: Docker with Traefik as reverse proxy

  • Database: Postgres

  • Server config from the docker-compose file:

  web:
    image: alerta/alerta-web
    depends_on:
      - db
    volumes:
      - ./alerta/config.json:/web/config.json
    environment:
      - DATABASE_URL=postgres://postgres:postgres@db:5432/monitoring
      - AUTH_REQUIRED=True
      - ADMIN_USERS=admin@alerta.io,devops@alerta.io
      - PLUGINS=reject,blackout,normalise,enhance,prometheus
      - USE_PROXYFIX=True
      - BASE_URL=/alerta
    restart: always
    networks:
      traefik_proxy:
        aliases:
          - alerta
    container_name: alerta
    labels:
      - "namespace=Monitoring"
      - "traefik.backend=alerta"
      #- "traefik.frontend.rule=Host:sub1.example.com;PathPrefix:/alerta, /config.json, /js"
      - "traefik.frontend.rule=Host:sub1.example.com;PathPrefix:/alerta"
      - "traefik.enable=true"
      - "traefik.port=8080"
      - "traefik.passHostHeader=true"

I’ve created two traefik.frontend.rules to test. If I use the one with multiple PathPrefix settings it’s ‘mostly’ working but there are still some issues I haven’t yet fully identified. There are also some javascript files from the /js folder loaded from / instead of the BASE_URL.

config.json:

{"endpoint": "https://sub1.example.com", "base_path": "/alerta/api" }

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@satterly yes, those sed replacements only work for assests, so i ended up building alerta-webui with BASE_URL set to “/alerta/”

@Madic- you might need to do something like this

FROM node:lts-alpine as build-stage
RUN wget https://github.com/alerta/alerta-webui/archive/v7.4.0.tar.gz -O - | tar -xz -C / \
 && cd /alerta-webui-master && echo "BASE_URL=/alerta/" > .env \
 && npm install && npm run build

FROM whatever-you-are-into as production-stage
COPY --from=build-stage /alerta-webui-master/dist /web
#...

i have a similar problem and as far as i can see, when getLocalConfig is called the path for the configuration file gets concatenated to just /config.json because process.env.BASE_URL is hardcoded to /. shouldn’t this be a relative path since no configuration have been loaded yet?

original config.ts

getLocalConfig() {
  const basePath = process.env.BASE_URL
  return this.$http
    .get('${basePath}config.json')
    .then(response => response.data)
    .catch((error: any) => {
      console.warn(error.message)
    })
}

unminified app.f24b8480.js

key: "getLocalConfig",
value: function() {
    var t = "/";
    return this.$http.get("".concat(t, "config.json")).then(function(t) {
        return t.data
    }).catch(function(t) {
        console.warn(t.message)
    })
}

test Dockerfile

FROM nginx:stable-alpine

RUN wget https://github.com/alerta/alerta-webui/releases/latest/download/alerta-webui.tar.gz -O - | tar -xz -C / \
 && echo '{"endpoint": "http://localhost:8000/alerta/api"}' > /dist/config.json \
 && chown -R nginx. /dist \
 && echo "daemon off;" >> /etc/nginx/nginx.conf \
 && echo "server {listen 8000; location /alerta {index index.html;alias /dist;}}" > /etc/nginx/conf.d/default.conf \
# this is another issue
 && sed -i "s#\(href\|src\|content\)\(=/\)\(js\|css\|fonts\|apple\|favicon\|mstile\)#\1\2alerta/\3#g" /dist/index.html

EXPOSE 8000/tcp
ENTRYPOINT ["nginx"]

Can’t attach the files directly so I’ve packed them in the following zip archive: config.zip