Merge pull request #4774 from DSpace/backport-4638-to-dspace-9_x

[Port dspace-9_x] Client side rendering (CSR) ignores `nameSpace` configuration causing broken resource loading
This commit is contained in:
Tim Donohue
2025-10-13 15:52:23 -05:00
committed by GitHub

View File

@@ -309,13 +309,24 @@ function serverSideRender(req, res, next, sendToUser: boolean = true) {
});
}
/**
* Send back response to user to trigger direct client-side rendering (CSR)
* @param req current request
* @param res current response
*/
// Read file once at startup
const indexHtmlContent = readFileSync(indexHtml, 'utf8');
function clientSideRender(req, res) {
res.sendFile(indexHtml);
const namespace = environment.ui.nameSpace || '/';
let html = indexHtmlContent;
// Replace base href dynamically
html = html.replace(
/<base href="[^"]*">/,
`<base href="${namespace.endsWith('/') ? namespace : namespace + '/'}">`
);
// Replace REST URL with UI URL
if (environment.ssr.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
html = html.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
}
res.send(html);
}