@@ -53,7 +53,7 @@ import { buildAppConfig } from './src/config/config.server';
5353import { APP_CONFIG , AppConfig } from './src/config/app-config.interface' ;
5454import { extendEnvironmentWithAppConfig } from './src/config/config.util' ;
5555import { logStartupMessage } from './startup-message' ;
56- import { TOKENITEM } from 'src/app/core/auth/models/auth-token-info.model' ;
56+ import { TOKENITEM } from './ src/app/core/auth/models/auth-token-info.model' ;
5757
5858
5959/*
@@ -374,9 +374,15 @@ function cacheCheck(req, res, next) {
374374 }
375375
376376 // If cached copy exists, return it to the user.
377- if ( cachedCopy ) {
377+ if ( cachedCopy && cachedCopy . page ) {
378+ if ( cachedCopy . headers && Array . isArray ( environment . cache . serverSide . headers ) && environment . cache . serverSide . headers . length > 0 ) {
379+ environment . cache . serverSide . headers . forEach ( ( header ) => {
380+ if ( environment . cache . serverSide . debug ) { console . log ( `Restore cached ${ header } header` ) ; }
381+ res . setHeader ( header , cachedCopy . headers [ header . toLowerCase ( ) ] ) ;
382+ } ) ;
383+ }
378384 res . locals . ssr = true ; // mark response as SSR-generated (enables text compression)
379- res . send ( cachedCopy ) ;
385+ res . send ( cachedCopy . page ) ;
380386
381387 // Tell Express to skip all other handlers for this path
382388 // This ensures we don't try to re-render the page since we've already returned the cached copy
@@ -452,16 +458,18 @@ function saveToCache(req, page: any) {
452458 // Avoid caching "/reload/[random]" paths (these are hard refreshes after logout)
453459 if ( key . startsWith ( '/reload' ) ) { return ; }
454460
461+ // Retrieve response headers
462+ const headers = req . res . getHeaders ( ) ;
455463 // If bot cache is enabled, save it to that cache if it doesn't exist or is expired
456464 // (NOTE: has() will return false if page is expired in cache)
457465 if ( botCacheEnabled ( ) && ! botCache . has ( key ) ) {
458- botCache . set ( key , page ) ;
466+ botCache . set ( key , { page, headers } ) ;
459467 if ( environment . cache . serverSide . debug ) { console . log ( `CACHE SAVE FOR ${ key } in bot cache.` ) ; }
460468 }
461469
462470 // If anonymous cache is enabled, save it to that cache if it doesn't exist or is expired
463471 if ( anonymousCacheEnabled ( ) && ! anonymousCache . has ( key ) ) {
464- anonymousCache . set ( key , page ) ;
472+ anonymousCache . set ( key , { page, headers } ) ;
465473 if ( environment . cache . serverSide . debug ) { console . log ( `CACHE SAVE FOR ${ key } in anonymous cache.` ) ; }
466474 }
467475 }
0 commit comments