@@ -26,15 +26,14 @@ import * as ejs from 'ejs';
2626import * as compression from 'compression' ;
2727import * as expressStaticGzip from 'express-static-gzip' ;
2828/* eslint-enable import/no-namespace */
29-
3029import axios from 'axios' ;
3130import LRU from 'lru-cache' ;
3231import isbot from 'isbot' ;
3332import { createCertificate } from 'pem' ;
3433import { createServer } from 'https' ;
3534import { json } from 'body-parser' ;
3635
37- import { existsSync , readFileSync } from 'fs' ;
36+ import { readFileSync } from 'fs' ;
3837import { join } from 'path' ;
3938
4039import { enableProdMode } from '@angular/core' ;
@@ -54,7 +53,7 @@ import { buildAppConfig } from './src/config/config.server';
5453import { APP_CONFIG , AppConfig } from './src/config/app-config.interface' ;
5554import { extendEnvironmentWithAppConfig } from './src/config/config.util' ;
5655import { logStartupMessage } from './startup-message' ;
57- 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' ;
5857
5958
6059/*
@@ -180,6 +179,15 @@ export function app() {
180179 changeOrigin : true
181180 } ) ) ;
182181
182+ /**
183+ * Proxy the linksets
184+ */
185+ router . use ( '/signposting**' , createProxyMiddleware ( {
186+ target : `${ environment . rest . baseUrl } ` ,
187+ pathRewrite : path => path . replace ( environment . ui . nameSpace , '/' ) ,
188+ changeOrigin : true
189+ } ) ) ;
190+
183191 /**
184192 * Checks if the rateLimiter property is present
185193 * When it is present, the rateLimiter will be enabled. When it is undefined, the rateLimiter will be disabled.
@@ -366,9 +374,19 @@ function cacheCheck(req, res, next) {
366374 }
367375
368376 // If cached copy exists, return it to the user.
369- if ( cachedCopy ) {
377+ if ( cachedCopy && cachedCopy . page ) {
378+ if ( cachedCopy . headers ) {
379+ Object . keys ( cachedCopy . headers ) . forEach ( ( header ) => {
380+ if ( cachedCopy . headers [ header ] ) {
381+ if ( environment . cache . serverSide . debug ) {
382+ console . log ( `Restore cached ${ header } header` ) ;
383+ }
384+ res . setHeader ( header , cachedCopy . headers [ header ] ) ;
385+ }
386+ } ) ;
387+ }
370388 res . locals . ssr = true ; // mark response as SSR-generated (enables text compression)
371- res . send ( cachedCopy ) ;
389+ res . send ( cachedCopy . page ) ;
372390
373391 // Tell Express to skip all other handlers for this path
374392 // This ensures we don't try to re-render the page since we've already returned the cached copy
@@ -444,21 +462,38 @@ function saveToCache(req, page: any) {
444462 // Avoid caching "/reload/[random]" paths (these are hard refreshes after logout)
445463 if ( key . startsWith ( '/reload' ) ) { return ; }
446464
465+ // Retrieve response headers to save, if any
466+ const headers = retrieveHeaders ( req . res ) ;
447467 // If bot cache is enabled, save it to that cache if it doesn't exist or is expired
448468 // (NOTE: has() will return false if page is expired in cache)
449469 if ( botCacheEnabled ( ) && ! botCache . has ( key ) ) {
450- botCache . set ( key , page ) ;
470+ botCache . set ( key , { page, headers } ) ;
451471 if ( environment . cache . serverSide . debug ) { console . log ( `CACHE SAVE FOR ${ key } in bot cache.` ) ; }
452472 }
453473
454474 // If anonymous cache is enabled, save it to that cache if it doesn't exist or is expired
455475 if ( anonymousCacheEnabled ( ) && ! anonymousCache . has ( key ) ) {
456- anonymousCache . set ( key , page ) ;
476+ anonymousCache . set ( key , { page, headers } ) ;
457477 if ( environment . cache . serverSide . debug ) { console . log ( `CACHE SAVE FOR ${ key } in anonymous cache.` ) ; }
458478 }
459479 }
460480}
461481
482+ function retrieveHeaders ( response ) {
483+ const headers = Object . create ( { } ) ;
484+ if ( Array . isArray ( environment . cache . serverSide . headers ) && environment . cache . serverSide . headers . length > 0 ) {
485+ environment . cache . serverSide . headers . forEach ( ( header ) => {
486+ if ( response . hasHeader ( header ) ) {
487+ if ( environment . cache . serverSide . debug ) {
488+ console . log ( `Save ${ header } header to cache` ) ;
489+ }
490+ headers [ header ] = response . getHeader ( header ) ;
491+ }
492+ } ) ;
493+ }
494+
495+ return headers ;
496+ }
462497/**
463498 * Whether a user is authenticated or not
464499 */
0 commit comments