@@ -26,6 +26,7 @@ const execFileAsync = promisify(execFile);
2626const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
2727const app = express ( ) ;
2828const PORT = Number ( process . env . PORT ) || 3001 ;
29+ app . disable ( "etag" ) ;
2930
3031// ── Rate limiting ─────────────────────────────────────────────────────────────
3132// Limits each IP to 120 requests per minute to prevent abuse.
@@ -39,7 +40,33 @@ app.use(limiter);
3940
4041// ── Static files (production build) ─────────────────────────────────────────
4142const distPath = path . join ( __dirname , "dist" ) ;
42- app . use ( express . static ( distPath ) ) ;
43+ app . use ( "/api" , ( _req , res , next ) => {
44+ res . set ( {
45+ "Cache-Control" : "no-store, no-cache, must-revalidate, proxy-revalidate" ,
46+ Pragma : "no-cache" ,
47+ Expires : "0" ,
48+ "Surrogate-Control" : "no-store" ,
49+ } ) ;
50+ next ( ) ;
51+ } ) ;
52+
53+ app . use (
54+ express . static ( distPath , {
55+ etag : false ,
56+ setHeaders : ( res , filePath ) => {
57+ if ( filePath . endsWith ( ".html" ) ) {
58+ res . setHeader ( "Cache-Control" , "no-store, no-cache, must-revalidate, proxy-revalidate" ) ;
59+ res . setHeader ( "Pragma" , "no-cache" ) ;
60+ res . setHeader ( "Expires" , "0" ) ;
61+ return ;
62+ }
63+
64+ if ( / \. [ A - Z a - z 0 - 9 _ - ] + \. ( j s | c s s ) $ / . test ( path . basename ( filePath ) ) ) {
65+ res . setHeader ( "Cache-Control" , "public, max-age=31536000, immutable" ) ;
66+ }
67+ } ,
68+ } )
69+ ) ;
4370
4471// ── Helpers ──────────────────────────────────────────────────────────────────
4572
@@ -671,6 +698,11 @@ app.get("/api/router/devices", async (req, res) => {
671698
672699// ── SPA fallback ─────────────────────────────────────────────────────────────
673700app . get ( "/{*path}" , ( _req , res ) => {
701+ res . set ( {
702+ "Cache-Control" : "no-store, no-cache, must-revalidate, proxy-revalidate" ,
703+ Pragma : "no-cache" ,
704+ Expires : "0" ,
705+ } ) ;
674706 res . sendFile ( path . join ( distPath , "index.html" ) ) ;
675707} ) ;
676708
0 commit comments