Skip to content

Commit 15b9c09

Browse files
[DURACOM-344] refactor solution
1 parent ccc5cc1 commit 15b9c09

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

server.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ export function app() {
209209

210210
/**
211211
* Default sending all incoming requests to ngApp() function, after first checking for a cached
212-
* copy of the page (see cacheAndErrorStatusCheck())
212+
* copy of the page (see cacheCheck())
213213
*/
214-
router.get('*', cacheAndErrorStatusCheck, ngApp);
214+
router.get('*', cacheCheck, ngApp);
215215

216216
server.use(environment.ui.nameSpace, router);
217217

@@ -375,7 +375,7 @@ function anonymousCacheEnabled(): boolean {
375375
* Check if the currently requested page is in our server-side, in-memory cache.
376376
* Caching is ONLY done for SSR requests. Pages are cached base on their path (e.g. /home or /search?query=test)
377377
*/
378-
function cacheAndErrorStatusCheck(req, res, next) {
378+
function cacheCheck(req, res, next) {
379379
// Cached copy of page (if found)
380380
let cachedCopy;
381381

@@ -399,7 +399,6 @@ function cacheAndErrorStatusCheck(req, res, next) {
399399
});
400400
}
401401
res.locals.ssr = true; // mark response as SSR-generated (enables text compression)
402-
setRequestErrorStatus(req, res);
403402
res.send(cachedCopy.page);
404403

405404
// Tell Express to skip all other handlers for this path
@@ -408,25 +407,10 @@ function cacheAndErrorStatusCheck(req, res, next) {
408407
} else {
409408
// If nothing found in cache, just continue with next handler
410409
// (This should send the request on to the handler that rerenders the page via SSR
411-
setRequestErrorStatus(req, res);
412410
next();
413411
}
414412
}
415413

416-
/**
417-
* Set request status code when serving an error page from SSR
418-
* @param req
419-
* @param res
420-
*/
421-
function setRequestErrorStatus(req, res) {
422-
if (req.url === getPageInternalServerErrorRoute()) {
423-
res.status(500)
424-
} else if (req.url === getPageNotFoundRoute()) {
425-
res.status(404)
426-
} else if (req.url === getForbiddenRoute()) {
427-
res.status(403)
428-
}
429-
}
430414

431415
/**
432416
* Checks if the current request (i.e. page) is found in the given cache. If it is found,

src/environments/environment.production.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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+
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/', '/500', '/404', '/403' ],
1414
enableSearchComponent: false,
1515
enableBrowseComponent: false,
1616
},

0 commit comments

Comments
 (0)