diff --git a/.gitlab-ci/values.yaml b/.gitlab-ci/values.yaml index 1337231dfa3c9c1bbbf3f9867867277f60f633ce..3b6a05611637ef89893d18ab2623f7e0cb99c87f 100644 --- a/.gitlab-ci/values.yaml +++ b/.gitlab-ci/values.yaml @@ -2,8 +2,8 @@ replicaCount: 1 containerPort: 8080 -manifests: - - http://main-core-ui.appsuite-stack-1494-main.svc.cluster.local/manifest.json +baseUrls: + - http://main-core-ui.appsuite-stack-1494-main.svc.cluster.local ingress: enabled: false diff --git a/helm/core-manifest-service/templates/configMap.yaml b/helm/core-manifest-service/templates/configMap.yaml index 94bcef71ccc22ff0b7519a9a84d8ab2f6e033787..c6c6a7d163e8eafc134c020db2a50dd8f9ea8940 100644 --- a/helm/core-manifest-service/templates/configMap.yaml +++ b/helm/core-manifest-service/templates/configMap.yaml @@ -4,7 +4,7 @@ kind: ConfigMap metadata: name: {{ include "ox-common.names.fullname" . }} data: - urls.yaml: | - manifests: - {{- toYaml .Values.manifests | nindent 6 }} + config.yaml: | + baseUrls: + {{- toYaml .Values.baseUrls | nindent 6 }} {{- end }} diff --git a/helm/core-manifest-service/templates/deployment.yaml b/helm/core-manifest-service/templates/deployment.yaml index dd7d259b4a7cc32832ba436321a046578253e1f7..a3f173a305032fbd529b3226554ea9ba6000b231 100644 --- a/helm/core-manifest-service/templates/deployment.yaml +++ b/helm/core-manifest-service/templates/deployment.yaml @@ -49,7 +49,7 @@ spec: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: - name: manifest-config - mountPath: /app/config/manifests + mountPath: /app/config/ volumes: - name: manifest-config configMap: diff --git a/helm/core-manifest-service/values.yaml b/helm/core-manifest-service/values.yaml index 83eb51d5dda7fcf26748746fa39020ce1e5c7d42..ff2ea44d732b9683d667c26c9e4cc114c8fd724b 100644 --- a/helm/core-manifest-service/values.yaml +++ b/helm/core-manifest-service/values.yaml @@ -101,5 +101,5 @@ probe: cacheTTL: 30000 logLevel: info -manifests: [] +baseUrls: [] appRoot: '/' diff --git a/helm/values/develop.yaml b/helm/values/develop.yaml index 7fe143d14dc9865f190f62689e144abb5871e97e..dd0afd7799d74d2e2a98c6041d71b13f5b8a676f 100644 --- a/helm/values/develop.yaml +++ b/helm/values/develop.yaml @@ -1,6 +1,6 @@ replicaCount: 1 containerPort: 8080 -manifests: +baseUrls: - https://manifest-service-dummy.k3s.os.oxui.de/manifest.json ingress: enabled: true diff --git a/spec/file-depencies_test.js b/spec/file-depencies_test.js index 15a619f3a141a936ed91e3a097cea8aaea1c9b27..f3b4f219f32c9c7fbaf8fce9a142397c5686fce8 100644 --- a/spec/file-depencies_test.js +++ b/spec/file-depencies_test.js @@ -11,9 +11,9 @@ describe('JS files with dependencies contain events', () => { beforeAll(() => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/api/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port}` } }) app = createApp() @@ -26,7 +26,7 @@ describe('JS files with dependencies contain events', () => { beforeEach(async () => { mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ + '/manifest.json': generateSimpleViteManifest({ 'example.js': {}, 'main.css': {}, 'index.html': { diff --git a/spec/file_caching_test.js b/spec/file_caching_test.js index 65359a874245b3d97a59c19bfaa7c8b4d5858d65..0fd09b8b0442173b9ffe92d810d5ffe1d195bae3 100644 --- a/spec/file_caching_test.js +++ b/spec/file_caching_test.js @@ -15,9 +15,9 @@ describe('File caching service', () => { beforeAll(() => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port}/` } }) app = createApp() diff --git a/spec/headers_test.js b/spec/headers_test.js index 93f572cde9118eab366ab2c90f54d9c8a18864ee..e9233577dfe350e6acf162afac9b50c8bd918fec 100644 --- a/spec/headers_test.js +++ b/spec/headers_test.js @@ -11,9 +11,9 @@ describe('Responses contain custom headers', () => { beforeAll(() => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/api/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port}` } }) app = createApp() @@ -26,7 +26,7 @@ describe('Responses contain custom headers', () => { beforeEach(async () => { mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ + '/manifest.json': generateSimpleViteManifest({ 'example.js': {}, 'main.css': {}, 'index.html': { diff --git a/spec/meta_test.js b/spec/meta_test.js index c866b84561c05a98d599011a86d85595087e8018..42b6f1cdfce9f8dc084fc16d67fe5da28252d840 100644 --- a/spec/meta_test.js +++ b/spec/meta_test.js @@ -11,9 +11,9 @@ describe('Responses contain custom headers', () => { beforeAll(() => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port}` } }) app = createApp() diff --git a/spec/server_test.js b/spec/server_test.js index 6079386f4688b894276ba6576d92c3bf3eeb8407..662b28bbbfdbabfe36944eb7ce899de99d44bb5c 100644 --- a/spec/server_test.js +++ b/spec/server_test.js @@ -6,14 +6,15 @@ import { createMockServer, generateSimpleViteManifest, getRandomPort } from './u describe('Manifest service', () => { let app - let mockserver + let mockserver, mockserver2 const port = getRandomPort() + const port2 = getRandomPort() beforeAll(() => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/api/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port}` } }) app = createApp() @@ -26,13 +27,14 @@ describe('Manifest service', () => { beforeEach(async () => { mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ 'example.js': 'test' }), + '/manifest.json': generateSimpleViteManifest({ 'example.js': 'test' }), '/example.js': '' }) }) afterEach(() => { - mockserver.close() + mockserver?.close() + mockserver2?.close() process.env.CACHE_TTL = 30000 }) @@ -58,7 +60,7 @@ describe('Manifest service', () => { mockserver.close() mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ 'example.js': 'other' }), + '/manifest.json': generateSimpleViteManifest({ 'example.js': 'other' }), '/example.js': '' }) @@ -80,7 +82,7 @@ describe('Manifest service', () => { mockserver.close() mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ 'example.js': 'other' }), + '/manifest.json': generateSimpleViteManifest({ 'example.js': 'other' }), '/example.js': '' }) @@ -94,19 +96,22 @@ describe('Manifest service', () => { it('can load multiple configurations', async () => { mockfs({ - './config/manifests': { - 'urls.yaml': `manifests: - - http://localhost:${port}/api/manifest.json - - http://localhost:${port}/api/no2/manifest.json` + './config': { + 'config.yaml': `baseUrls: + - http://localhost:${port} + - http://localhost:${port2}` } }) mockserver.close() mockserver = await createMockServer({ port }) mockserver.respondWith({ - '/api/manifest.json': generateSimpleViteManifest({ 'example1.js': 'other' }), - '/api/no2/manifest.json': generateSimpleViteManifest({ 'example2.js': 'thing' }), - '/example1.js': '', + '/manifest.json': generateSimpleViteManifest({ 'example1.js': 'other' }), + '/example1.js': '' + }) + mockserver2 = await createMockServer({ port: port2 }) + mockserver2.respondWith({ + '/manifest.json': generateSimpleViteManifest({ 'example2.js': 'thing' }), '/example2.js': '' }) diff --git a/src/config.js b/src/config.js index 2747ac60a64b32f682f56bcb859c02cd8f0ef1d7..b6e21d97a71bbd395c81da2f5a575772450788bd 100644 --- a/src/config.js +++ b/src/config.js @@ -3,8 +3,8 @@ import yaml from 'js-yaml' class Config { async load () { - const urlsSource = await fs.readFile('./config/manifests/urls.yaml', 'utf8') - this._urls = yaml.load(urlsSource).manifests + const urlsSource = await fs.readFile('./config/config.yaml', 'utf8') + this._urls = yaml.load(urlsSource).baseUrls } get urls () { diff --git a/src/manifests.js b/src/manifests.js index c5d654500d350a95050bae28adbd8b668a571ce4..cc608c6598dabfef08fed0b4ea1c05f7fe7dd2c9 100644 --- a/src/manifests.js +++ b/src/manifests.js @@ -15,17 +15,16 @@ export const loadViteManifests = (() => { await config.load() // vite manifests contains a set of objects with the vite-manifests // from the corresponding registered services - const viteManifests = await Promise.all(config.urls.map(async url => { - const { origin } = new URL(url) + const viteManifests = await Promise.all(config.urls.map(async baseUrl => { // fetch the manifests - const result = await fetch(url) + const result = await fetch(new URL('/manifest.json', baseUrl)) if (!result.ok) throw new Error(`Failed to load manifest for url ${result.url} (Status: ${result.status}: ${result.statusText})`) try { const manifest = await result.json() for (const file in manifest) { - logger.debug(`retrieved ${file} from ${url}`) + logger.debug(`retrieved ${file} from ${baseUrl}`) manifest[file].meta = manifest[file].meta || {} - manifest[file].meta.baseUrl = origin + manifest[file].meta.baseUrl = baseUrl } return manifest } catch (err) {