From 28a9f92dffc5876ba16b13d3d37b9981f87eece2 Mon Sep 17 00:00:00 2001
From: Richard Petersen <richard.petersen@open-xchange.com>
Date: Fri, 18 Nov 2022 14:24:28 +0100
Subject: [PATCH] Set cache control to no-store. The ui-middleware will then
 only look at the remote servers for the files and never in the local cache

---
 integration/config_test.js         | 2 +-
 integration/update-version_test.js | 2 +-
 spec/file_caching_test.js          | 6 +++---
 spec/util.js                       | 2 +-
 src/files.js                       | 2 +-
 src/manifests.js                   | 2 +-
 src/meta.js                        | 2 +-
 src/version.js                     | 4 ++--
 8 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/integration/config_test.js b/integration/config_test.js
index e6b8826..5d807de 100644
--- a/integration/config_test.js
+++ b/integration/config_test.js
@@ -18,7 +18,7 @@ describe('Configuration', function () {
           'index.html': {}
         }),
         '/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }),
-        '/meta.json': td.when(td.func()(td.matchers.anything())).thenReturn(
+        '/meta.json': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn(
           new Response(JSON.stringify({ commitSha: '1' }), { headers: { 'Content-Type': 'application/json' } }),
           new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } })
         )
diff --git a/integration/update-version_test.js b/integration/update-version_test.js
index 15d3fc7..0d40a75 100644
--- a/integration/update-version_test.js
+++ b/integration/update-version_test.js
@@ -17,7 +17,7 @@ describe('Updates the version', function () {
           'index.html': {}
         }),
         '/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }),
-        '/meta.json': td.when(td.func()(td.matchers.anything())).thenReturn(
+        '/meta.json': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn(
           new Response(JSON.stringify({ commitSha: '1' }), { headers: { 'Content-Type': 'application/json' } }),
           new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } }),
           new Response(JSON.stringify({ commitSha: '2' }), { headers: { 'Content-Type': 'application/json' } })
diff --git a/spec/file_caching_test.js b/spec/file_caching_test.js
index 3803ddb..cd6f198 100644
--- a/spec/file_caching_test.js
+++ b/spec/file_caching_test.js
@@ -237,7 +237,7 @@ describe('File caching service', function () {
         '/manifest.json': generateSimpleViteManifest({
           'example.js': { }
         }),
-        '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn(
+        '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn(
           new Response('first', { headers: { 'content-type': 'text/plain' } }),
           new Response('second', { headers: { 'content-type': 'text/plain' } })
         )
@@ -275,7 +275,7 @@ describe('File caching service', function () {
         '/manifest.json': generateSimpleViteManifest({
           'example.js': { }
         }),
-        '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn(
+        '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn(
           new Response('UI-container not available', { headers: { 'content-type': 'text/plain' }, status: 503 }),
           new Response('Now available', { headers: { 'content-type': 'text/plain' } })
         )
@@ -298,7 +298,7 @@ describe('File caching service', function () {
         '/manifest.json': generateSimpleViteManifest({
           'example.js': { }
         }),
-        '/example.js': td.when(td.func()(td.matchers.anything())).thenReturn(
+        '/example.js': td.when(td.func()(td.matchers.anything(), td.matchers.anything())).thenReturn(
           new Response('Not found', { headers: { 'content-type': 'text/plain' }, status: 404 }),
           new Response('Now found', { headers: { 'content-type': 'text/plain' } })
         )
diff --git a/spec/util.js b/spec/util.js
index 23c361c..a052a3c 100644
--- a/spec/util.js
+++ b/spec/util.js
@@ -25,7 +25,7 @@ export function mockConfig (obj = {}) {
 }
 
 export function mockFetch (servers = {}) {
-  td.replace(global, 'fetch', async function ({ origin, pathname }) {
+  td.replace(global, 'fetch', async function ({ origin, pathname }, ...args) {
     const response = servers[origin]?.[pathname]
     if (response === undefined) return new Response('', { status: 404 })
     if (response instanceof Function) return response.apply(this, arguments)
diff --git a/src/files.js b/src/files.js
index 757ff49..c9f27e0 100644
--- a/src/files.js
+++ b/src/files.js
@@ -34,7 +34,7 @@ async function createFileBuffer (response, dependencies) {
 
 export async function fetchFileWithHeadersFromBaseUrl (path, baseUrl, version) {
   const [response, dependencies] = await Promise.all([
-    fetch(new URL(path, baseUrl)),
+    fetch(new URL(path, baseUrl), { cache: 'no-store' }),
     isJSFile(path) && getCSSDependenciesFor({ file: path.substr(1), version })
   ])
 
diff --git a/src/manifests.js b/src/manifests.js
index 14f71a0..209a726 100644
--- a/src/manifests.js
+++ b/src/manifests.js
@@ -11,7 +11,7 @@ export async function fetchViteManifests () {
   // from the corresponding registered services
   const viteManifests = await Promise.all(configMap.urls.map(async baseUrl => {
     // fetch the manifests
-    const result = await fetch(new URL('manifest.json', baseUrl))
+    const result = await fetch(new URL('manifest.json', baseUrl), { cache: 'no-store' })
     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()
diff --git a/src/meta.js b/src/meta.js
index 4f6209a..c6d5761 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -6,7 +6,7 @@ export async function fetchMergedMetadata () {
   const metadata = await Promise.all(configMap.urls.map(async url => {
     const { origin } = new URL(url)
     try {
-      const response = await fetch(new URL('meta.json', origin))
+      const response = await fetch(new URL('meta.json', origin), { cache: 'no-store' })
       if (!response.ok) return
       return response.json()
     } catch (e) {
diff --git a/src/version.js b/src/version.js
index 615a095..e87b7da 100644
--- a/src/version.js
+++ b/src/version.js
@@ -27,7 +27,7 @@ const versionUpdateGauge = new Gauge({
 export const fetchLatestVersion = async () => {
   const infos = await Promise.all(configMap.urls.map(async baseUrl => {
     try {
-      const response = await fetch(new URL('meta.json', baseUrl))
+      const response = await fetch(new URL('meta.json', baseUrl), { cache: 'no-store' })
       if (!response.ok) throw new Error()
       const meta = await response.json()
       const version = meta.commitSha || meta.buildDate || meta.version
@@ -36,7 +36,7 @@ export const fetchLatestVersion = async () => {
     } catch (err) {
       logger.warn(`[Version] UI container at ${baseUrl} does not have meta.json. Fall back to version hash based on manifest.`)
     }
-    const response = await fetch(new URL('manifest.json', baseUrl))
+    const response = await fetch(new URL('manifest.json', baseUrl), { cache: 'no-store' })
     if (!response.ok) throw new Error(`Cannot fetch manifest.json from ${baseUrl}`)
     const manifest = await response.json()
     return hash(manifest)
-- 
GitLab