Skip to content

Commit 5cbec37

Browse files
[DURACOM-344] refactor solution to avoid double slashes
(cherry picked from commit c442d35)
1 parent d4231e0 commit 5cbec37

File tree

6 files changed

+77
-45
lines changed

6 files changed

+77
-45
lines changed

config/config.example.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ ssr:
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
@@ -58,6 +58,7 @@ import {
5858
REQUEST,
5959
RESPONSE,
6060
} from './src/express.tokens';
61+
import { SsrExcludePatterns } from "./src/config/ssr-config.interface";
6162

6263
/*
6364
* Set path for the browser application's dist folder
@@ -633,9 +634,11 @@ function start() {
633634
* @param path
634635
* @param excludePathPattern
635636
*/
636-
function isExcludedFromSsr(path: string, excludePathPattern: (string | RegExp)[]): boolean {
637-
return excludePathPattern.some((pattern) => {
638-
const regex = new RegExp(pattern);
637+
function isExcludedFromSsr(path: string, excludePathPattern: SsrExcludePatterns[]): boolean {
638+
const patterns = excludePathPattern.map(p =>
639+
new RegExp(p.pattern, p.flag || '')
640+
);
641+
return patterns.some((regex) => {
639642
return regex.test(path)
640643
});
641644
}

src/config/ssr-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 SSRConfig extends Config {
49
/**
510
* A boolean flag indicating whether the SSR configuration is enabled
@@ -41,7 +46,7 @@ export interface SSRConfig extends Config {
4146
/**
4247
* Patterns to be used as regexes to match url's path and check if SSR is disabled for it.
4348
*/
44-
excludePathPatterns: (string | RegExp)[];
49+
excludePathPatterns: SsrExcludePatterns[];
4550

4651
/**
4752
* 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
@@ -11,16 +11,23 @@ export const environment: Partial<BuildConfig> = {
1111
transferState: true,
1212
replaceRestUrl: true,
1313
excludePathPatterns: [
14-
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
15-
/^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
16-
/^\/browse\//,
17-
/^\/search$/,
18-
/^\/community-list$/,
19-
/^\/statistics\//,
20-
/^\/admin$/,
21-
/^\/processes$/,
22-
/^\/notifications$/,
23-
/^\/health$/,
14+
{
15+
pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
16+
flag: 'i',
17+
},
18+
{
19+
pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
20+
flag: 'i',
21+
},
22+
{ pattern: '^/browse/' },
23+
{ pattern: '^/search' },
24+
{ pattern: '^/community-list$' },
25+
{ pattern: '^/statistics/?' },
26+
{ pattern: '^/admin/' },
27+
{ pattern: '^/processes/?' },
28+
{ pattern: '^/notifications/' },
29+
{ pattern: '^/access-control/' },
30+
{ pattern: '^/health$' },
2431
],
2532
enableSearchComponent: false,
2633
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
@@ -16,16 +16,23 @@ export const environment: Partial<BuildConfig> = {
1616
transferState: true,
1717
replaceRestUrl: false,
1818
excludePathPatterns: [
19-
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
20-
/^\/collections\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
21-
/^\/browse\//,
22-
/^\/search$/,
23-
/^\/community-list$/,
24-
/^\/statistics\//,
25-
/^\/admin$/,
26-
/^\/processes$/,
27-
/^\/notifications$/,
28-
/^\/health$/,
19+
{
20+
pattern: '^/communities/[a-f0-9-]{36}/browse(/.*)?$',
21+
flag: 'i',
22+
},
23+
{
24+
pattern: '^/collections/[a-f0-9-]{36}/browse(/.*)?$',
25+
flag: 'i',
26+
},
27+
{ pattern: '^/browse/' },
28+
{ pattern: '^/search' },
29+
{ pattern: '^/community-list$' },
30+
{ pattern: '^/statistics/?' },
31+
{ pattern: '^/admin/' },
32+
{ pattern: '^/processes/?' },
33+
{ pattern: '^/notifications/' },
34+
{ pattern: '^/access-control/' },
35+
{ pattern: '^/health$' },
2936
],
3037
enableSearchComponent: false,
3138
enableBrowseComponent: false,

0 commit comments

Comments
 (0)