From c442d355057adc6b6bcf27dde9138019c9e15d55 Mon Sep 17 00:00:00 2001 From: FrancescoMolinaro Date: Mon, 12 May 2025 17:34:07 +0200 Subject: [PATCH] [DURACOM-344] refactor solution to avoid double slashes --- config/config.example.yml | 25 +++++++++++--------- server.ts | 9 +++++--- src/config/ssr-config.interface.ts | 7 +++++- src/environments/environment.production.ts | 27 ++++++++++++++-------- src/environments/environment.test.ts | 27 ++++++++++++++-------- src/environments/environment.ts | 27 ++++++++++++++-------- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index f90d821a35..a9de709dea 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -25,18 +25,21 @@ ssr: 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 7cf475c239..cf21eda6af 100644 --- a/server.ts +++ b/server.ts @@ -58,6 +58,7 @@ import { REQUEST, RESPONSE, } from './src/express.tokens'; +import { SsrExcludePatterns } from "./src/config/ssr-config.interface"; /* * Set path for the browser application's dist folder @@ -633,9 +634,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/ssr-config.interface.ts b/src/config/ssr-config.interface.ts index ee39512d44..16bb3f54d6 100644 --- a/src/config/ssr-config.interface.ts +++ b/src/config/ssr-config.interface.ts @@ -1,5 +1,10 @@ import { Config } from './config.interface'; +export interface SsrExcludePatterns { + pattern: string | RegExp; + flag?: string; +} + export interface SSRConfig extends Config { /** * A boolean flag indicating whether the SSR configuration is enabled @@ -41,7 +46,7 @@ export interface SSRConfig 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 238c45c21e..21cc8a25ea 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -11,16 +11,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 44f0760123..ee59d09d73 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 cd773664fc..2b6b6d9fd8 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -16,16 +16,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,