diff --git a/config/config.example.yml b/config/config.example.yml index 25949ba4918..139c4e7ebc6 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -23,6 +23,8 @@ ssr: # Determining which styles are critical is a relatively expensive operation; this option is # disabled (false) by default to boost server performance at the expense of loading smoothness. inlineCriticalCss: false + # Path prefixes to enable SSR for. By default these are limited to paths of primary DSpace objects. + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ] # The REST API server settings # NOTE: these settings define which (publicly available) REST API to use. They are usually diff --git a/server.ts b/server.ts index 032b79b8f25..8c5978937f2 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' && (req.path === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) { // 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..35b0d394083 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/', '/handle/' ], }, }; diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index c7146dfb078..84229aa6591 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/', '/handle/' ], }, // Angular express server settings. diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 0292c19200b..a02ef4a2a96 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/', '/handle/' ], }, };