Skip to content

Commit c0e71a0

Browse files
[DURACOM-344] refactor solution to avoid double slashes
1 parent 21ac024 commit c0e71a0

6 files changed

Lines changed: 77 additions & 45 deletions

File tree

config/config.example.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ universal:
2525
inlineCriticalCss: false
2626
# Patterns to be run as regexes against the path of the page to check if SSR is allowed.
2727
# If the path match any of the regexes it will be served directly in CSR.
28-
# By default, excludes community and collection browse, global browse, global search, community list, and statistics.
28+
# By default, excludes community and collection browse, global browse, global search, community list, statistics and various administrative tools.
2929
excludePathPatterns:
30-
- /^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i
31-
- /^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i
32-
- /^\/browse\//
33-
- /^\/search$/
34-
- /^\/community-list$/
35-
- /^\/statistics\//
36-
- /^\/admin$/
37-
- /^\/processes$/
38-
- /^\/notifications$/
39-
- /^\/health$/
30+
- pattern: "^/communities/[a-f0-9-]{36}/browse(/.*)?$",
31+
flag: "i"
32+
- pattern: "^/collections/[a-f0-9-]{36}/browse(/.*)?$"
33+
flag: "i"
34+
- pattern: "^/browse/"
35+
- pattern: "^/search$"
36+
- pattern: "^/community-list$"
37+
- pattern: "^/admin/"
38+
- pattern: "^/processes/?"
39+
- pattern: "^/notifications/"
40+
- pattern: "^/statistics/?"
41+
- pattern: "^/access-control/"
42+
- pattern: "^/health$"
4043

4144
# Whether to enable rendering of Search component on SSR.
4245
# If set to true the component will be included in the HTML returned from the server side rendering.

server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
5555
import { extendEnvironmentWithAppConfig } from './src/config/config.util';
5656
import { logStartupMessage } from './startup-message';
5757
import { TOKENITEM } from './src/app/core/auth/models/auth-token-info.model';
58+
import { SsrExcludePatterns } from './src/config/universal-config.interface';
5859

5960

6061
/*
@@ -631,9 +632,11 @@ function start() {
631632
* @param path
632633
* @param excludePathPattern
633634
*/
634-
function isExcludedFromSsr(path: string, excludePathPattern: (string | RegExp)[]): boolean {
635-
return excludePathPattern.some((pattern) => {
636-
const regex = new RegExp(pattern);
635+
function isExcludedFromSsr(path: string, excludePathPattern: SsrExcludePatterns[]): boolean {
636+
const patterns = excludePathPattern.map(p =>
637+
new RegExp(p.pattern, p.flag || '')
638+
);
639+
return patterns.some((regex) => {
637640
return regex.test(path)
638641
});
639642
}

src/config/universal-config.interface.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Config } from './config.interface';
22

3+
export interface SsrExcludePatterns {
4+
pattern: string | RegExp;
5+
flag?: string;
6+
}
7+
38
export interface UniversalConfig extends Config {
49
preboot: boolean;
510
async: boolean;
@@ -34,7 +39,7 @@ export interface UniversalConfig extends Config {
3439
/**
3540
* Patterns to be used as regexes to match url's path and check if SSR is disabled for it.
3641
*/
37-
excludePathPatterns: (string | RegExp)[];
42+
excludePathPatterns: SsrExcludePatterns[];
3843

3944
/**
4045
* Whether to enable rendering of search component on SSR

src/environments/environment.production.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ export const environment: Partial<BuildConfig> = {
1212
transferState: true,
1313
replaceRestUrl: true,
1414
excludePathPatterns: [
15-
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
16-
/^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
17-
/^\/browse\//,
18-
/^\/search$/,
19-
/^\/community-list$/,
20-
/^\/statistics\//,
21-
/^\/admin$/,
22-
/^\/processes$/,
23-
/^\/notifications$/,
24-
/^\/health$/,
15+
{
16+
pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
17+
flag: 'i',
18+
},
19+
{
20+
pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
21+
flag: 'i',
22+
},
23+
{ pattern: '^/browse/' },
24+
{ pattern: '^/search' },
25+
{ pattern: '^/community-list$' },
26+
{ pattern: '^/statistics/?' },
27+
{ pattern: '^/admin/' },
28+
{ pattern: '^/processes/?' },
29+
{ pattern: '^/notifications/' },
30+
{ pattern: '^/access-control/' },
31+
{ pattern: '^/health$' },
2532
],
2633
enableSearchComponent: false,
2734
enableBrowseComponent: false,

src/environments/environment.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@ export const environment: BuildConfig = {
1515
transferState: true,
1616
replaceRestUrl: false,
1717
excludePathPatterns: [
18-
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
19-
/^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
20-
/^\/browse\//,
21-
/^\/search$/,
22-
/^\/community-list$/,
23-
/^\/statistics\//,
24-
/^\/admin$/,
25-
/^\/processes$/,
26-
/^\/notifications$/,
27-
/^\/health$/,
18+
{
19+
pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
20+
flag: 'i',
21+
},
22+
{
23+
pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
24+
flag: 'i',
25+
},
26+
{ pattern: '^/browse/' },
27+
{ pattern: '^/search' },
28+
{ pattern: '^/community-list$' },
29+
{ pattern: '^/statistics/?' },
30+
{ pattern: '^/admin/' },
31+
{ pattern: '^/processes/?' },
32+
{ pattern: '^/notifications/' },
33+
{ pattern: '^/access-control/' },
34+
{ pattern: '^/health$' },
2835
],
2936
enableSearchComponent: false,
3037
enableBrowseComponent: false,

src/environments/environment.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,23 @@ export const environment: Partial<BuildConfig> = {
1717
transferState: true,
1818
replaceRestUrl: false,
1919
excludePathPatterns: [
20-
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
21-
/^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
22-
/^\/browse\//,
23-
/^\/search$/,
24-
/^\/community-list$/,
25-
/^\/statistics\//,
26-
/^\/admin$/,
27-
/^\/processes$/,
28-
/^\/notifications$/,
29-
/^\/health$/,
20+
{
21+
pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
22+
flag: 'i',
23+
},
24+
{
25+
pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
26+
flag: 'i',
27+
},
28+
{ pattern: '^/browse/' },
29+
{ pattern: '^/search' },
30+
{ pattern: '^/community-list$' },
31+
{ pattern: '^/statistics/?' },
32+
{ pattern: '^/admin/' },
33+
{ pattern: '^/processes/?' },
34+
{ pattern: '^/notifications/' },
35+
{ pattern: '^/access-control/' },
36+
{ pattern: '^/health$' },
3037
],
3138
enableSearchComponent: false,
3239
enableBrowseComponent: false,

0 commit comments

Comments
 (0)