Skip to content
Snippets Groups Projects
Commit 28a9f92d authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

Set cache control to no-store. The ui-middleware will then only look at the...

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
parent 74ceae10
No related branches found
No related tags found
No related merge requests found
......@@ -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' } })
)
......
......@@ -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' } })
......
......@@ -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' } })
)
......
......@@ -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)
......
......@@ -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 })
])
......
......@@ -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()
......
......@@ -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) {
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment