Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,24 @@ function serverSideRender(req, res, 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.universal.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
html = html.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
}

res.send(html);
}


Expand Down
Loading