Skip to content

Commit c399976

Browse files
[DURACOM-344] set error pages status in response
[DURACOM-344] name refactor [DURACOM-344] remove hardcoded paths [DURACOM-344] refactor solution [DURACOM-344] remove import [DURACOM-344] switch to blacklist approach for SSR [DURACOM-344] adapt regex to enable base com/col path [DURACOM-344] refactor
1 parent 9a24fb2 commit c399976

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

config/config.example.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +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 enable SSR for. By default these are limited to paths of primary DSpace objects.
27-
# NOTE: The "/handle/" path ensures Handle redirects work via SSR. The "/reload/" path ensures
28-
# hard refreshes (e.g. after login) trigger SSR while fully reloading the page.
29-
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ]
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}(\/.*)?$/]
3029
# Whether to enable rendering of Search component on SSR.
3130
# If set to true the component will be included in the HTML returned from the server side rendering.
3231
# If set to false the component will not be included in the HTML returned from the server side rendering.

server.ts

+11-1
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 === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) {
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 {
@@ -627,6 +627,16 @@ function start() {
627627
}
628628
}
629629

630+
/**
631+
* Check if SSR should be skipped for path
632+
*
633+
* @param path
634+
* @param excludePathRegexes
635+
*/
636+
function isExcludedFromSsr(path: string, excludePathRegexes: RegExp[]): boolean {
637+
return excludePathRegexes.some((regex) => regex.test(path));
638+
}
639+
630640
/*
631641
* The callback function to serve health check requests
632642
*/

src/config/ssr-config.interface.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export interface SSRConfig extends Config {
3939
replaceRestUrl: boolean;
4040

4141
/**
42-
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
42+
* Regexes to match url's path and check if SSR is disabled for it.
4343
*/
44-
paths: Array<string>;
44+
excludePathRegexes: RegExp[];
4545

4646
/**
4747
* Whether to enable rendering of search component on SSR

src/environments/environment.production.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ export const environment: Partial<BuildConfig> = {
1010
inlineCriticalCss: false,
1111
transferState: true,
1212
replaceRestUrl: true,
13-
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
13+
excludePathRegexes: [
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+
],
1421
enableSearchComponent: false,
1522
enableBrowseComponent: false,
1623
},

src/environments/environment.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export const environment: BuildConfig = {
1414
inlineCriticalCss: false,
1515
transferState: true,
1616
replaceRestUrl: false,
17-
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
17+
excludePathRegexes: [
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+
],
1825
enableSearchComponent: false,
1926
enableBrowseComponent: false,
2027
},

src/environments/environment.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export const environment: Partial<BuildConfig> = {
1515
inlineCriticalCss: false,
1616
transferState: true,
1717
replaceRestUrl: false,
18-
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
18+
excludePathRegexes: [
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+
],
1926
enableSearchComponent: false,
2027
enableBrowseComponent: false,
2128
},

0 commit comments

Comments
 (0)