[DURACOM-344] Adapt SSR page filtering mechanism to a not allowed list

This commit is contained in:
FrancescoMolinaro
2025-04-22 16:16:27 +02:00
parent 9a24fb2b64
commit b1c5460bbb
6 changed files with 48 additions and 10 deletions

View File

@@ -221,7 +221,7 @@ export function app() {
* The callback function to serve server side angular
*/
function ngApp(req, res, next) {
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || environment.ssr.paths.some(pathPrefix => req.path.startsWith(pathPrefix)))) {
if (environment.ssr.enabled && req.method === 'GET' && (req.path === '/' || !isExcludedFromSsr(req.path, environment.ssr.excludePathRegexes))) {
// Render the page to user via SSR (server side rendering)
serverSideRender(req, res, next);
} else {
@@ -627,6 +627,16 @@ function start() {
}
}
/**
* Check if SSR should be skipped for path
*
* @param path
* @param excludePathRegexes
*/
function isExcludedFromSsr(path: string, excludePathRegexes: RegExp[]): boolean {
return excludePathRegexes.some((regex) => regex.test(path));
}
/*
* The callback function to serve health check requests
*/