11import compression from 'compression' ;
22import express from 'express' ;
3+ import { readFile } from 'fs/promises' ;
4+ import helmet from 'helmet' ;
35import morgan from 'morgan' ;
46import * as path from 'path' ;
7+ import { createServer } from 'vite' ;
58import { initializePuppeteerCluster } from './application/screenshot' ;
9+ import { getSurveyTitle } from './application/survey' ;
610import { configureAuth , configureMockAuth , ensureAuthenticated } from './auth' ;
711import { getDb , initializeDatabase , migrateUp } from './database' ;
12+ import { startUpdatingRefreshToken } from './email/refresh-token' ;
813import { HttpResponseError } from './error' ;
914import logger from './logger' ;
1015import rootRouter from './routes' ;
11- import helmet from 'helmet' ;
12- import { readFile } from 'fs/promises' ;
13- import { createServer } from 'vite' ;
14- import { getSurveyTitle } from './application/survey' ;
15- import { startUpdatingRefreshToken } from './email/refresh-token' ;
16+
17+ function setNoCacheForIndex ( res : express . Response , filePath : string ) {
18+ if ( filePath . endsWith ( 'index.html' ) ) {
19+ res . setHeader ( 'Cache-Control' , 'no-cache, no-store' ) ;
20+ }
21+ }
22+
23+ const noCacheConfig = {
24+ 'Cache-Control' : 'no-cache, no-store' ,
25+ } ;
1626
1727const isDev = process . env . NODE_ENV === 'development' ;
1828
@@ -128,9 +138,9 @@ async function start() {
128138 ensureAuthenticated ( {
129139 redirectToLogin : true ,
130140 } ) ,
131- express . static ( 'static/admin' ) ,
141+ express . static ( 'static/admin' , { setHeaders : setNoCacheForIndex } ) ,
132142 ) ;
133- app . use ( '/' , express . static ( 'static' ) ) ;
143+ app . use ( '/' , express . static ( 'static' , { setHeaders : setNoCacheForIndex } ) ) ;
134144
135145 // Root router for the API
136146 app . use ( '/api' , rootRouter ) ;
@@ -142,7 +152,9 @@ async function start() {
142152 redirectToLogin : true ,
143153 } ) ,
144154 ( _req , res ) => {
145- res . sendFile ( path . join ( __dirname , '../static/admin/index.html' ) ) ;
155+ res
156+ . set ( noCacheConfig )
157+ . sendFile ( path . join ( __dirname , '../static/admin/index.html' ) ) ;
146158 } ,
147159 ) ;
148160
@@ -183,7 +195,10 @@ async function start() {
183195 . replaceAll ( `<!--app-title -->` , title )
184196 . replace ( '@clientSrc' , 'src' ) ;
185197
186- res . status ( 200 ) . set ( { 'Content-Type' : 'text/html' } ) . end ( renderedHtml ) ;
198+ res
199+ . status ( 200 )
200+ . set ( { 'Content-Type' : 'text/html' , ...noCacheConfig } )
201+ . end ( renderedHtml ) ;
187202 } catch ( e : any ) {
188203 isDev && vite . ssrFixStacktrace ( e ) ;
189204 logger . error ( e . stack ) ;
0 commit comments