Skip to content

Commit 791b022

Browse files
milanmajchrakgithub-actions[bot]
authored andcommitted
Added rendering namespace when client side
(cherry picked from commit 75c9112)
1 parent 3448d1c commit 791b022

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.universal.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)