From e6fa667639c171597577573352a63ee8d2bf02a1 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Mon, 8 Mar 2021 11:37:35 +0100 Subject: [PATCH] Update type and changeset Signed-off-by: Dominik Henneke --- .changeset/good-humans-draw.md | 4 ++-- plugins/app-backend/src/service/router.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.changeset/good-humans-draw.md b/.changeset/good-humans-draw.md index ff9bacaa49..3e97fa15b6 100644 --- a/.changeset/good-humans-draw.md +++ b/.changeset/good-humans-draw.md @@ -2,5 +2,5 @@ '@backstage/plugin-app-backend': patch --- -Add a `Cache-Control: no-store` header to the `index.html` response to instruct the browser to not cache the pages. -This is a workaround for a missing `staticFallbackHandler` since an old `index.html` might link to static assets from a previous deployment. +Add a `Cache-Control: no-store, max-age=0` header to the `index.html` response to instruct the browser to not cache the pages. +This tells the browser to not serve a cached `index.html` that might link to static assets from a previous deployment that are not available anymore. diff --git a/plugins/app-backend/src/service/router.ts b/plugins/app-backend/src/service/router.ts index fec300bace..d140c73180 100644 --- a/plugins/app-backend/src/service/router.ts +++ b/plugins/app-backend/src/service/router.ts @@ -23,6 +23,9 @@ import { resolve as resolvePath } from 'path'; import { Logger } from 'winston'; import { injectConfig, readConfigs } from '../lib/config'; +// express uses mime v1 while we only have types for mime v2 +type Mime = { lookup(arg0: string): string }; + export interface RouterOptions { config: Config; logger: Logger; @@ -101,8 +104,10 @@ export async function createRouter( // The Cache-Control header instructs the browser to not cache html files since it might // link to static assets from recently deployed versions. This is a workaround when no // staticFallbackHandler is configured. - // use `as any` since express uses mime v1 while we only have types for mime v2 - if ((express.static.mime as any).lookup(path) === 'text/html') { + if ( + ((express.static.mime as unknown) as Mime).lookup(path) === + 'text/html' + ) { res.setHeader('Cache-Control', 'no-store, max-age=0'); } },