From 55a030d38355f3e16899ae8e44a99839aaeba0aa Mon Sep 17 00:00:00 2001 From: Alexey Zinoviev Date: Fri, 21 Jun 2024 12:59:02 +0400 Subject: [PATCH] UBERF-7362: Do not cache branding served from front (#5889) Signed-off-by: Alexey Zinoviev --- dev/docker-compose.yaml | 1 + dev/prod/src/platform.ts | 2 +- server/front/src/index.ts | 14 +++++++++++++- tests/docker-compose.yaml | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dev/docker-compose.yaml b/dev/docker-compose.yaml index 7e9aed0735..3528843d8f 100644 --- a/dev/docker-compose.yaml +++ b/dev/docker-compose.yaml @@ -84,6 +84,7 @@ services: - COLLABORATOR_URL=ws://localhost:3078 - COLLABORATOR_API_URL=http://localhost:3078 - STORAGE_CONFIG=${STORAGE_CONFIG} + - BRANDING_URL=http://localhost:8087/branding.json restart: unless-stopped collaborator: image: hardcoreeng/collaborator diff --git a/dev/prod/src/platform.ts b/dev/prod/src/platform.ts index 1cfad1b913..bc1dee68eb 100644 --- a/dev/prod/src/platform.ts +++ b/dev/prod/src/platform.ts @@ -205,7 +205,7 @@ export async function configurePlatform() { configureI18n() const config: Config = await (await fetch(devConfig? '/config-dev.json' : '/config.json')).json() - const branding: BrandingMap = await (await fetch(config.BRANDING_URL ?? '/branding.json')).json() + const branding: BrandingMap = config.BRANDING_URL !== undefined ? await (await fetch(config.BRANDING_URL)).json() : {} const myBranding = branding[window.location.host] ?? {} console.log('loading configuration', config) diff --git a/server/front/src/index.ts b/server/front/src/index.ts index b9326dd306..ca3098872d 100644 --- a/server/front/src/index.ts +++ b/server/front/src/index.ts @@ -304,6 +304,15 @@ export function start ( const dist = resolve(process.env.PUBLIC_DIR ?? cwd(), 'dist') console.log('serving static files from', dist) + let brandingUrl: URL | undefined + if (config.brandingUrl !== undefined) { + try { + brandingUrl = new URL(config.brandingUrl) + } catch (e) { + console.error('Invalid branding URL. Must be absolute URL.', e) + } + } + app.use( expressStaticGzip(dist, { serveStatic: { @@ -314,7 +323,10 @@ export function start ( lastModified: true, index: false, setHeaders (res, path) { - if (path.toLowerCase().includes('index.html')) { + if ( + path.toLowerCase().includes('index.html') || + (brandingUrl !== undefined && path.toLowerCase().includes(brandingUrl.pathname)) + ) { res.setHeader('Cache-Control', cacheControlNoCache) } } diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml index af42520640..bd4bad6002 100644 --- a/tests/docker-compose.yaml +++ b/tests/docker-compose.yaml @@ -78,7 +78,7 @@ services: - COLLABORATOR_URL=ws://localhost:3079 - COLLABORATOR_API_URL=http://localhost:3079 - STORAGE_CONFIG=${STORAGE_CONFIG} - - BRANDING_URL=/branding-test.json + - BRANDING_URL=http://localhost:8083/branding-test.json transactor: image: hardcoreeng/transactor pull_policy: never