diff --git a/config/config.yml b/config/config.yml
index 6016a55b498..9257bd2b09d 100644
--- a/config/config.yml
+++ b/config/config.yml
@@ -6,6 +6,38 @@ rest:
port: 8080
nameSpace: /server
+universal:
+ # Whether to tell Angular to inline "critical" styles into the server-side rendered HTML.
+ # Determining which styles are critical is a relatively expensive operation; this option is
+ # disabled (false) by default to boost server performance at the expense of loading smoothness.
+ inlineCriticalCss: false
+ # Patterns to be run as regexes against the path of the page to check if SSR is allowed.
+ # If the path match any of the regexes it will be served directly in CSR.
+ # By default, excludes community and collection browse, global browse, global search, community list, statistics and various administrative tools.
+ excludePathPatterns:
+ - pattern: "^/communities/[a-f0-9-]{36}/browse(/.*)?$"
+ flag: "i"
+ - pattern: "^/collections/[a-f0-9-]{36}/browse(/.*)?$"
+ flag: "i"
+ - pattern: "^/browse/"
+ - pattern: "^/search$"
+ - pattern: "^/community-list$"
+ - pattern: "^/admin/"
+ - pattern: "^/processes/?"
+ - pattern: "^/notifications/"
+ - pattern: "^/statistics/?"
+ - pattern: "^/access-control/"
+ - pattern: "^/health$"
+
+ # Whether to enable rendering of Search component on SSR.
+ # If set to true the component will be included in the HTML returned from the server side rendering.
+ # If set to false the component will not be included in the HTML returned from the server side rendering.
+ enableSearchComponent: false
+ # Whether to enable rendering of Browse component on SSR.
+ # If set to true the component will be included in the HTML returned from the server side rendering.
+ # If set to false the component will not be included in the HTML returned from the server side rendering.
+ enableBrowseComponent: false
+
# Caching settings
cache:
# NOTE: how long should objects be cached for by default
diff --git a/server.ts b/server.ts
index 091a4b79d38..d92310746e9 100644
--- a/server.ts
+++ b/server.ts
@@ -273,10 +273,6 @@ function serverSideRender(req, res, sendToUser: boolean = true) {
requestUrl: req.originalUrl,
}, (err, data) => {
if (hasNoValue(err) && hasValue(data)) {
- // Fix missing base href in SSR output
- const baseHref = `${environment.ui.nameSpace}${environment.ui.nameSpace.endsWith('/') ? '' : '/'}`;
- data = data.replace(//, ``);
-
// Replace REST URL with UI URL
if (environment.universal.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
data = data.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
@@ -307,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(
+ //,
+ ``
+ );
+
+ // 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);
}