From 29ecb5cf758c6b84cca8e40ffd75b4bf2c6305bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20B=C3=A4ume?= <julian.baeume@open-xchange.com>
Date: Thu, 28 Oct 2021 17:19:40 +0200
Subject: [PATCH] allow specification of app root

this can not only be handled on ingress level, but we need to mount the
express app also on the app root level. This basically just works out of the
box.
---
 .env.defaults                                        | 1 +
 helm/core-manifest-service/templates/deployment.yaml | 2 ++
 helm/core-manifest-service/values.yaml               | 2 ++
 src/index.js                                         | 6 +++++-
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/.env.defaults b/.env.defaults
index 1e9c2b0..d89fd29 100644
--- a/.env.defaults
+++ b/.env.defaults
@@ -1,3 +1,4 @@
 CACHE_TTL=30000
 PORT=8080
 LOG_LEVEL=info
+APP_ROOT=/
diff --git a/helm/core-manifest-service/templates/deployment.yaml b/helm/core-manifest-service/templates/deployment.yaml
index 5eca31e..e29cb76 100644
--- a/helm/core-manifest-service/templates/deployment.yaml
+++ b/helm/core-manifest-service/templates/deployment.yaml
@@ -25,6 +25,8 @@ spec:
               value: "{{ .Values.cacheTTL | int }}"
             - name: LOG_LEVEL
               value: "{{ .Values.logLevel }}"
+            - name: APP_ROOT
+              value: "{{ .Values.appRoot }}"
           ports:
             - name: http
               containerPort: {{ .Values.containerPort | default 8080 }}
diff --git a/helm/core-manifest-service/values.yaml b/helm/core-manifest-service/values.yaml
index a2476fb..a87d172 100644
--- a/helm/core-manifest-service/values.yaml
+++ b/helm/core-manifest-service/values.yaml
@@ -98,3 +98,5 @@ probe:
 
 cacheTTL: 30000
 logLevel: info
+manifests: []
+appRoot: '/'
diff --git a/src/index.js b/src/index.js
index 84dbe3a..6696302 100644
--- a/src/index.js
+++ b/src/index.js
@@ -3,12 +3,16 @@
 import { config } from 'dotenv-defaults'
 import { getLogger } from './logger.js'
 import { createApp } from './createApp.js'
+import express from 'express'
 
 config()
 
+const root = express()
 const app = createApp()
 
 // Binds and listens for connections on the specified host and port
-app.listen(process.env.PORT, () => {
+root.listen(process.env.PORT, () => {
   getLogger().info(`manifest-service listening on port ${process.env.PORT}`)
 })
+
+root.use(process.env.APP_ROOT, app)
-- 
GitLab