Skip to content

Commit aea7e7b

Browse files
authored
Merge pull request #4638 from dataquest-dev/csr-namespace-rendering
Client side rendering (CSR) ignores `nameSpace` configuration causing broken resource loading
2 parents 28ed706 + 75c9112 commit aea7e7b

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
@@ -303,13 +303,24 @@ function serverSideRender(req, res, sendToUser: boolean = true) {
303303
});
304304
}
305305

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

315326

0 commit comments

Comments
 (0)