[DURACOM-344] refactor solution to avoid double slashes

This commit is contained in:
FrancescoMolinaro
2025-05-12 17:34:07 +02:00
parent 21ac024423
commit c0e71a0e68
6 changed files with 77 additions and 45 deletions

View File

@@ -25,18 +25,21 @@ universal:
inlineCriticalCss: false inlineCriticalCss: false
# Patterns to be run as regexes against the path of the page to check if SSR is allowed. # 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. # 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: excludePathPatterns:
- /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i - pattern: "^/communities/[a-f0-9-]{36}/browse(/.*)?$",
- /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i flag: "i"
- /^\/browse\// - pattern: "^/collections/[a-f0-9-]{36}/browse(/.*)?$"
- /^\/search$/ flag: "i"
- /^\/community-list$/ - pattern: "^/browse/"
- /^\/statistics\// - pattern: "^/search$"
- /^\/admin$/ - pattern: "^/community-list$"
- /^\/processes$/ - pattern: "^/admin/"
- /^\/notifications$/ - pattern: "^/processes/?"
- /^\/health$/ - pattern: "^/notifications/"
- pattern: "^/statistics/?"
- pattern: "^/access-control/"
- pattern: "^/health$"
# Whether to enable rendering of Search component on SSR. # 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. # If set to true the component will be included in the HTML returned from the server side rendering.

View File

@@ -55,6 +55,7 @@ import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
import { extendEnvironmentWithAppConfig } from './src/config/config.util'; import { extendEnvironmentWithAppConfig } from './src/config/config.util';
import { logStartupMessage } from './startup-message'; import { logStartupMessage } from './startup-message';
import { TOKENITEM } from './src/app/core/auth/models/auth-token-info.model'; 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 path
* @param excludePathPattern * @param excludePathPattern
*/ */
function isExcludedFromSsr(path: string, excludePathPattern: (string | RegExp)[]): boolean { function isExcludedFromSsr(path: string, excludePathPattern: SsrExcludePatterns[]): boolean {
return excludePathPattern.some((pattern) => { const patterns = excludePathPattern.map(p =>
const regex = new RegExp(pattern); new RegExp(p.pattern, p.flag || '')
);
return patterns.some((regex) => {
return regex.test(path) return regex.test(path)
}); });
} }

View File

@@ -1,5 +1,10 @@
import { Config } from './config.interface'; import { Config } from './config.interface';
export interface SsrExcludePatterns {
pattern: string | RegExp;
flag?: string;
}
export interface UniversalConfig extends Config { export interface UniversalConfig extends Config {
preboot: boolean; preboot: boolean;
async: 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. * 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 * Whether to enable rendering of search component on SSR

View File

@@ -12,16 +12,23 @@ export const environment: Partial<BuildConfig> = {
transferState: true, transferState: true,
replaceRestUrl: true, replaceRestUrl: true,
excludePathPatterns: [ 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, pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
/^\/browse\//, flag: 'i',
/^\/search$/, },
/^\/community-list$/, {
/^\/statistics\//, pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
/^\/admin$/, flag: 'i',
/^\/processes$/, },
/^\/notifications$/, { pattern: '^/browse/' },
/^\/health$/, { pattern: '^/search' },
{ pattern: '^/community-list$' },
{ pattern: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
], ],
enableSearchComponent: false, enableSearchComponent: false,
enableBrowseComponent: false, enableBrowseComponent: false,

View File

@@ -15,16 +15,23 @@ export const environment: BuildConfig = {
transferState: true, transferState: true,
replaceRestUrl: false, replaceRestUrl: false,
excludePathPatterns: [ 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, pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
/^\/browse\//, flag: 'i',
/^\/search$/, },
/^\/community-list$/, {
/^\/statistics\//, pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
/^\/admin$/, flag: 'i',
/^\/processes$/, },
/^\/notifications$/, { pattern: '^/browse/' },
/^\/health$/, { pattern: '^/search' },
{ pattern: '^/community-list$' },
{ pattern: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
], ],
enableSearchComponent: false, enableSearchComponent: false,
enableBrowseComponent: false, enableBrowseComponent: false,

View File

@@ -17,16 +17,23 @@ export const environment: Partial<BuildConfig> = {
transferState: true, transferState: true,
replaceRestUrl: false, replaceRestUrl: false,
excludePathPatterns: [ 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, pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
/^\/browse\//, flag: 'i',
/^\/search$/, },
/^\/community-list$/, {
/^\/statistics\//, pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
/^\/admin$/, flag: 'i',
/^\/processes$/, },
/^\/notifications$/, { pattern: '^/browse/' },
/^\/health$/, { pattern: '^/search' },
{ pattern: '^/community-list$' },
{ pattern: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
], ],
enableSearchComponent: false, enableSearchComponent: false,
enableBrowseComponent: false, enableBrowseComponent: false,