apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "kubeapps.dashboard-config.fullname" . }}
  labels:{{ include "kubeapps.extraAppLabels" . | nindent 4 }}
    app: {{ template "kubeapps.dashboard-config.fullname" . }}
data:
  vhost.conf: |-
    server {
      listen 8080;
  {{- if .Values.frontend.largeClientHeaderBuffers }}
      large_client_header_buffers {{ .Values.frontend.largeClientHeaderBuffers }};
  {{- end }}
  {{- if .Values.enableIPv6 }}
      listen [::]:8080;
  {{- end}}
      server_name _;

      gzip on;
      gzip_static  on;

      location / {
        # Redirects are required to be relative otherwise the internal hostname will be exposed
        absolute_redirect off;

        # Trailing / is required in the path for the React app to be loaded correctly
        # The rewrite rule adds a trailing "/" to any path that does not contain "." neither "/".
        # i.e kubeapps => kubeapps/
        rewrite ^([^.]*[^/])$ $1/ permanent;

        # Support for ingress prefixes maintaining compatibility with the default /
        # 1 - Exactly two fragment URLs for files existing inside of the public/ dir
        # i.e /[prefix]/config.json => /config.json
        rewrite ^/[^/]+/([^/]+)$ /$1 break;

        # 2 - Any static files bundled by webpack referenced by 3 or more URL segments
        # i.e /[prefix]/static/main.js => static/main.js
        rewrite ^/[^/]+/static/(.*) /static/$1 break;

        try_files $uri /index.html;
      }
    }
  config.json: |-
    {
      "kubeappsCluster": "{{ template "kubeapps.kubeappsCluster" . -}}",
      "kubeappsNamespace": "{{ .Release.Namespace }}",
      "appVersion": "{{ .Chart.AppVersion }}",
      "authProxyEnabled": {{ .Values.authProxy.enabled }},
      "oauthLoginURI": {{ .Values.authProxy.oauthLoginURI | quote }},
      "oauthLogoutURI": {{ .Values.authProxy.oauthLogoutURI | quote }},
      "featureFlags": {{ .Values.featureFlags | toJson }},
      "clusters": {{ template "kubeapps.clusterNames" . }}
    }
