diff --git a/config/config.example.yml b/config/config.example.yml index 42e13038d0..c1d7f967a4 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 23d29723c6..82417f17dc 100644 --- a/server.ts +++ b/server.ts @@ -238,7 +238,7 @@ export function app() { * The callback function to serve server side angular */ function ngApp(req, res) { - if (environment.universal.preboot) { + if (environment.universal.preboot && req.method === 'GET' && (req.path === '/' || environment.universal.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) { // Render the page to user via SSR (server side rendering) serverSideRender(req, res); } else { diff --git a/src/config/universal-config.interface.ts b/src/config/universal-config.interface.ts index eb89264e37..e54168823f 100644 --- a/src/config/universal-config.interface.ts +++ b/src/config/universal-config.interface.ts @@ -13,4 +13,9 @@ export interface UniversalConfig extends Config { * loading smoothness. */ 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 931dd422e3..46a93519df 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -9,5 +9,6 @@ export const environment: Partial = { async: true, time: 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 cfd54781e6..e872285f61 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -12,6 +12,7 @@ export const environment: BuildConfig = { async: true, time: false, inlineCriticalCss: false, + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ], }, // Angular Universal server settings. diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 7c09793790..25af371e47 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -14,6 +14,7 @@ export const environment: Partial = { async: true, time: false, inlineCriticalCss: false, + paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/' ], } };