[SOLVED] Support for base url (reverse proxy and/or kubernetes ingress)

The web pages of mattermost don’t support “base url”. This makes me not being able to deploy mattermost in a kubernetes environment with ingress controller based on path:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-mattermost
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    ingress.kubernetes.io/add-base-url: "true"
spec:
  rules:
  - http:
      paths:
      - path: /mattermost
        backend:
          serviceName: mattermost
          servicePort: 80

The resulting HTML is as follows:

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <meta name="robots" content="noindex, nofollow">
    <meta name="referrer" content="no-referrer">
    <title>Mattermost</title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-title" content="Mattermost">
    <meta name="application-name" content="Mattermost">
    <meta name="format-detection" content="telephone=no">
    <link rel="apple-touch-icon" sizes="57x57" href="/static/files/787db8d8b82538cc1d5e8bcb8c21722d.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/static/files/cd9987714f4d92336c3ab203ff150a9a.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/static/files/1728fd5a009aabc77654b1f958c6f596.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/static/files/17cb12b7fc37d8229a6e72f3d6da0949.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/static/files/fba6362db1d8b3e27c9fb02fd0695c85.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/static/files/08959a08dc2488dfeb8660fc4630b145.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/static/files/bca263be9acd1df84b988b02c621b8ca.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/static/files/532142b052832f94ffc35860545a7e5c.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/static/files/c220e89731c31367c0f4e86e3442bee0.png">
    <link rel="icon" type="image/png" sizes="96x96" href="/static/files/173682cef105829829a008f1fc97e980.png">
    <link rel="icon" type="image/png" sizes="192x192" href="/static/files/0d367a00a16bde58f7e87c4481516a68.png">
    <link rel="manifest" href="/static/files/fee9721a6305a49662a40ffd052a7965.json">
    <link rel="stylesheet" class="code_theme">
    <script type="text/javascript" src="/static/main.85719f8a07aef45169c3.js"></script>
</head>
<body>
<div id="root">
    <div class="loading-screen" style="position:relative">
        <div class="loading__content">
            <div class="round round-1"></div>
            <div class="round round-2"></div>
            <div class="round round-3"></div>
        </div>
    </div>
</div>
<script>window.setup_root()</script>
<base href="https://s1s005my.be.srv.acc.sys/mattermost/">
</body>
</html>

And the following error (base url is not taken into account):

(index):1 GET https://s1s005my.be.srv.acc.sys/static/main.85719f8a07aef45169c3.js 
(index):1 Uncaught TypeError: window.setup_root is not a function
    at (index):1
(anonymous) @ (index):1

As an example/inspiration… the Grafana docker image (Docker) supports the specification of an ENV variable to tweak this as needed:

      env:
        - name: GF_SERVER_ROOT_URL
          value: /grafana

I have a temporary work-around for my kubernetes deployment that seems to work so far:

    lifecycle:
      postStart:
        exec:
          command:
            - "/bin/sh"
            - "-c"
            - >
              cd /mattermost/webapp/dist/ ;
              sed -i -e 's|/static/|/mattermost/static/|g' *.html ;
              sed -i -e 's|api/v3|mattermost/api/v3|g' *.js ;
              sed -i -e 's|"/static/"|"/mattermost/static/"|g' *.js ;

Hi @boeboe,

Thank you for your feedback,

Could we have your help opening a feature request on our forum so that you and others can up-vote it? The more popular a feature becomes, the more chance it has of making it into the product.

Thanks!