diff --git a/config/config.example.yml b/config/config.example.yml index 2b905148cd..1a127e083f 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -25,18 +25,21 @@ universal: inlineCriticalCss: false # Patterns to be run as regexes against the path of the page to check if SSR is allowed. # If the path match any of the regexes it will be served directly in CSR. - # By default, excludes community and collection browse, global browse, global search, community list, and statistics. + # By default, excludes community and collection browse, global browse, global search, community list, statistics and various administrative tools. excludePathPatterns: - - /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i - - /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i - - /^\/browse\// - - /^\/search$/ - - /^\/community-list$/ - - /^\/statistics\// - - /^\/admin$/ - - /^\/processes$/ - - /^\/notifications$/ - - /^\/health$/ + - pattern: "^/communities/[a-f0-9-]{36}/browse(/.*)?$", + flag: "i" + - pattern: "^/collections/[a-f0-9-]{36}/browse(/.*)?$" + flag: "i" + - pattern: "^/browse/" + - pattern: "^/search$" + - pattern: "^/community-list$" + - pattern: "^/admin/" + - pattern: "^/processes/?" + - pattern: "^/notifications/" + - pattern: "^/statistics/?" + - pattern: "^/access-control/" + - pattern: "^/health$" # Whether to enable rendering of Search component on SSR. # If set to true the component will be included in the HTML returned from the server side rendering. diff --git a/server.ts b/server.ts index a44407c0fc..0705214417 100644 --- a/server.ts +++ b/server.ts @@ -55,6 +55,7 @@ import { APP_CONFIG, AppConfig } from './src/config/app-config.interface'; import { extendEnvironmentWithAppConfig } from './src/config/config.util'; import { logStartupMessage } from './startup-message'; import { TOKENITEM } from './src/app/core/auth/models/auth-token-info.model'; +import { SsrExcludePatterns } from './src/config/universal-config.interface'; /* @@ -631,9 +632,11 @@ function start() { * @param path * @param excludePathPattern */ -function isExcludedFromSsr(path: string, excludePathPattern: (string | RegExp)[]): boolean { - return excludePathPattern.some((pattern) => { - const regex = new RegExp(pattern); +function isExcludedFromSsr(path: string, excludePathPattern: SsrExcludePatterns[]): boolean { + const patterns = excludePathPattern.map(p => + new RegExp(p.pattern, p.flag || '') + ); + return patterns.some((regex) => { return regex.test(path) }); } diff --git a/src/config/universal-config.interface.ts b/src/config/universal-config.interface.ts index 215730f75e..531f7d54d5 100644 --- a/src/config/universal-config.interface.ts +++ b/src/config/universal-config.interface.ts @@ -1,5 +1,10 @@ import { Config } from './config.interface'; +export interface SsrExcludePatterns { + pattern: string | RegExp; + flag?: string; +} + export interface UniversalConfig extends Config { preboot: boolean; async: boolean; @@ -34,7 +39,7 @@ export interface UniversalConfig extends Config { /** * Patterns to be used as regexes to match url's path and check if SSR is disabled for it. */ - excludePathPatterns: (string | RegExp)[]; + excludePathPatterns: SsrExcludePatterns[]; /** * Whether to enable rendering of search component on SSR diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 3fb08629e0..e5066ab48f 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -12,16 +12,23 @@ export const environment: Partial = { transferState: true, replaceRestUrl: true, excludePathPatterns: [ - /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/browse\//, - /^\/search$/, - /^\/community-list$/, - /^\/statistics\//, - /^\/admin$/, - /^\/processes$/, - /^\/notifications$/, - /^\/health$/, + { + pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { + pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { pattern: '^/browse/' }, + { pattern: '^/search' }, + { pattern: '^/community-list$' }, + { pattern: '^/statistics/?' }, + { pattern: '^/admin/' }, + { pattern: '^/processes/?' }, + { pattern: '^/notifications/' }, + { pattern: '^/access-control/' }, + { pattern: '^/health$' }, ], enableSearchComponent: false, enableBrowseComponent: false, diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index f04e76265c..29db39d899 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -15,16 +15,23 @@ export const environment: BuildConfig = { transferState: true, replaceRestUrl: false, excludePathPatterns: [ - /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/browse\//, - /^\/search$/, - /^\/community-list$/, - /^\/statistics\//, - /^\/admin$/, - /^\/processes$/, - /^\/notifications$/, - /^\/health$/, + { + pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { + pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { pattern: '^/browse/' }, + { pattern: '^/search' }, + { pattern: '^/community-list$' }, + { pattern: '^/statistics/?' }, + { pattern: '^/admin/' }, + { pattern: '^/processes/?' }, + { pattern: '^/notifications/' }, + { pattern: '^/access-control/' }, + { pattern: '^/health$' }, ], enableSearchComponent: false, enableBrowseComponent: false, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index fb81708cc6..11525e4790 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -17,16 +17,23 @@ export const environment: Partial = { transferState: true, replaceRestUrl: false, excludePathPatterns: [ - /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i, - /^\/browse\//, - /^\/search$/, - /^\/community-list$/, - /^\/statistics\//, - /^\/admin$/, - /^\/processes$/, - /^\/notifications$/, - /^\/health$/, + { + pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { + pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$', + flag: 'i', + }, + { pattern: '^/browse/' }, + { pattern: '^/search' }, + { pattern: '^/community-list$' }, + { pattern: '^/statistics/?' }, + { pattern: '^/admin/' }, + { pattern: '^/processes/?' }, + { pattern: '^/notifications/' }, + { pattern: '^/access-control/' }, + { pattern: '^/health$' }, ], enableSearchComponent: false, enableBrowseComponent: false,