Skip to content

Commit 26a2eae

Browse files
authored
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
2 parents 3448d1c + 6ae5f98 commit 26a2eae

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

server.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,24 @@ function serverSideRender(req, res, next, sendToUser: boolean = true) {
309309
});
310310
}
311311

312-
/**
313-
* Send back response to user to trigger direct client-side rendering (CSR)
314-
* @param req current request
315-
* @param res current response
316-
*/
312+
// Read file once at startup
313+
const indexHtmlContent = readFileSync(indexHtml, 'utf8');
314+
317315
function clientSideRender(req, res) {
318-
res.sendFile(indexHtml);
316+
const namespace = environment.ui.nameSpace || '/';
317+
let html = indexHtmlContent;
318+
// Replace base href dynamically
319+
html = html.replace(
320+
/<base href="[^"]*">/,
321+
`<base href="${namespace.endsWith('/') ? namespace : namespace + '/'}">`
322+
);
323+
324+
// Replace REST URL with UI URL
325+
if (environment.ssr.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
326+
html = html.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
327+
}
328+
329+
res.send(html);
319330
}
320331

321332

0 commit comments

Comments
 (0)