Skip to content

Commit 4af4306

Browse files
[DURACOM-344] refactor
1 parent 94f71c8 commit 4af4306

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

config/config.example.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ ssr:
2323
# Determining which styles are critical is a relatively expensive operation; this option is
2424
# disabled (false) by default to boost server performance at the expense of loading smoothness.
2525
inlineCriticalCss: false
26-
# Path prefixes to disable SSR for. If the path the user is visiting starts with one of the excluded paths, it will be served directly in CSR.
27-
# These should be limited to paths that might cause high consumption in resources (e.g. crawler on pages with many items to follow).
28-
excludePaths: ['/browse/', '/community-list', '/search/', '/statistics' ]
29-
# Regexes to be run against the URl of the page to check if SSR is allowed.
30-
# This configuration offers more flexibility and precision than excludePaths as we can match more complex URLs.
31-
# If the entire URL match any of the regexes it will be served directly in CSR.
32-
ssrBlacklistRegexes: [ /^\/communities\/[0-9a-fA-F-]{36}(\/.*)?$/, /^\/collections\/[0-9a-fA-F-]{36}(\/.*)?$/]
26+
# Regexes to be run against the path of the page to check if SSR is allowed.
27+
# If the path match any of the regexes it will be served directly in CSR.
28+
excludePathRegexes: [ /^\/communities\/[0-9a-fA-F-]{36}(\/.*)?$/, /^\/collections\/[0-9a-fA-F-]{36}(\/.*)?$/]
3329
# Whether to enable rendering of Search component on SSR.
3430
# If set to true the component will be included in the HTML returned from the server side rendering.
3531
# If set to false the component will not be included in the HTML returned from the server side rendering.

server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export function app() {
221221
* The callback function to serve server side angular
222222
*/
223223
function ngApp(req, res, next) {
224-
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || !isBlacklistedPathForSsr(req.url, req.path, environment.ssr.ssrBlacklistRegexes))) {
224+
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || !isExcludedFromSsr(req.path, environment.ssr.excludePathRegexes))) {
225225
// Render the page to user via SSR (server side rendering)
226226
serverSideRender(req, res, next);
227227
} else {
@@ -628,14 +628,13 @@ function start() {
628628
}
629629

630630
/**
631-
* Check if SSR should be skipped for url or path
631+
* Check if SSR should be skipped for path
632632
*
633-
* @param url
634633
* @param path
635-
* @param blacklist
634+
* @param excludePathRegexes
636635
*/
637-
function isBlacklistedPathForSsr(url: string, path: string, blacklist: RegExp[]): boolean {
638-
return blacklist.some((regex) => regex.test(url)) || environment.ssr.excludePaths.some(blacklistedPath => path.startsWith(blacklistedPath));
636+
function isExcludedFromSsr(path: string, excludePathRegexes: RegExp[]): boolean {
637+
return excludePathRegexes.some((regex) => regex.test(path));
639638
}
640639

641640
/*

src/config/ssr-config.interface.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ export interface SSRConfig extends Config {
3939
replaceRestUrl: boolean;
4040

4141
/**
42-
* Paths to disable SSR for, to avoid some possible performance issue for specific pages.
42+
* Regexes to match url's path and check if SSR is disabled for it.
4343
*/
44-
excludePaths: Array<string>;
45-
46-
/**
47-
* Regexes to match url and check if SSR is enabled for it.
48-
*/
49-
ssrBlacklistRegexes: RegExp[];
44+
excludePathRegexes: RegExp[];
5045

5146
/**
5247
* Whether to enable rendering of search component on SSR

src/environments/environment.production.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ export const environment: Partial<BuildConfig> = {
1010
inlineCriticalCss: false,
1111
transferState: true,
1212
replaceRestUrl: true,
13-
excludePaths: [ '/browse/', '/community-list', '/search/', '/statistics' ],
14-
ssrBlacklistRegexes: [
13+
excludePathRegexes: [
1514
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
1615
/^\/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$/,
1720
],
1821
enableSearchComponent: false,
1922
enableBrowseComponent: false,

src/environments/environment.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ export const environment: BuildConfig = {
1414
inlineCriticalCss: false,
1515
transferState: true,
1616
replaceRestUrl: false,
17-
excludePaths: [ '/browse/', '/community-list', '/search/', '/statistics' ],
18-
ssrBlacklistRegexes: [
17+
excludePathRegexes: [
1918
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
2019
/^\/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$/,
2124
],
2225
enableSearchComponent: false,
2326
enableBrowseComponent: false,

src/environments/environment.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export const environment: Partial<BuildConfig> = {
1515
inlineCriticalCss: false,
1616
transferState: true,
1717
replaceRestUrl: false,
18-
excludePaths: [ '/browse/', '/community-list', '/search/', '/statistics' ],
19-
ssrBlacklistRegexes: [
18+
excludePathRegexes: [
2019
/^\/communities\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/browse(\/.*)?$/i,
2120
/^\/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$/,
2225
],
2326
enableSearchComponent: false,
2427
enableBrowseComponent: false,

0 commit comments

Comments
 (0)