From 3d544f62e8e9bb2298f5451973560484d643deae 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. --- server.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server.ts b/server.ts index 07a05656d87..33e2df0a68d 100644 --- a/server.ts +++ b/server.ts @@ -72,6 +72,16 @@ const cookieParser = require('cookie-parser'); const appConfig: AppConfig = buildAppConfig(join(DIST_FOLDER, 'assets/config.json')); +// only enable SSR for paths in the sitemap +const SSR_PATHS = [ + '/items/', + '/entities/', + '/collections/', + '/communities/', + '/bitstream/', + '/bitstreams/' +]; + // cache of SSR pages for known bots, only enabled in production mode let botCache: LRU; @@ -218,7 +228,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' && SSR_PATHS.some(p => req.url.includes(p))) { // Render the page to user via SSR (server side rendering) serverSideRender(req, res, next); } else {