From eeccff21dac5c70a54dc867a28e56c0eb373e577 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Fri, 22 Nov 2024 12:29:32 +0300 Subject: [PATCH] server.ts: restrict SSR to paths in the sitemap Because Angular SSR is not very efficient, after discussion with the Google Scholar team we realized a compromise would be to only use SSR for pages in the DSpace sitemap (and the home page). --- server.ts | 2 +- src/config/ssr-config.interface.ts | 5 +++++ src/environments/environment.production.ts | 1 + src/environments/environment.test.ts | 1 + src/environments/environment.ts | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server.ts b/server.ts index 07a05656d87..cfdc310c001 100644 --- a/server.ts +++ b/server.ts @@ -218,7 +218,7 @@ export function app() { * The callback function to serve server side angular */ function ngApp(req, res, next) { - if (environment.ssr.enabled) { + if (environment.ssr.enabled && req.method === 'GET' && environment.ssr.paths.some(p => req.url.includes(p))) { // Render the page to user via SSR (server side rendering) serverSideRender(req, res, next); } else { diff --git a/src/config/ssr-config.interface.ts b/src/config/ssr-config.interface.ts index 37b8b4a0d2b..1a01e4d1257 100644 --- a/src/config/ssr-config.interface.ts +++ b/src/config/ssr-config.interface.ts @@ -20,4 +20,9 @@ export interface SSRConfig extends Config { * For improved SSR performance, DSpace defaults this to false (disabled). */ inlineCriticalCss: boolean; + + /** + * Paths to enable SSR for. Defaults to the home page and paths in the sitemap. + */ + paths: Array; } diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 90b219cdbd7..cf8e81ebf8a 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -8,5 +8,6 @@ export const environment: Partial = { enabled: true, enablePerformanceProfiler: false, inlineCriticalCss: false, + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ], }, }; diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index c7146dfb078..ed8ba3fbc30 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -12,6 +12,7 @@ export const environment: BuildConfig = { enabled: true, enablePerformanceProfiler: false, inlineCriticalCss: false, + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ], }, // Angular express server settings. diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 0292c19200b..df82f0455e3 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -13,6 +13,7 @@ export const environment: Partial = { enabled: false, enablePerformanceProfiler: false, inlineCriticalCss: false, + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ], }, };