Skip to content

Commit

Permalink
server.ts: restrict SSR to paths in the sitemap
Browse files Browse the repository at this point in the history
Because Angular SSR is not very efficient, after discussion with
the Google Scholar team we realized a compromise would be to only
use SSR for pages in the DSpace sitemap (and the home page).
  • Loading branch information
alanorth committed Dec 8, 2024
1 parent 5088567 commit 34c38b6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function app() {
* The callback function to serve server side angular
*/
function ngApp(req, res, next) {
if (environment.ssr.enabled) {
if (environment.ssr.enabled && req.method === 'GET' && environment.ssr.paths.some(p => req.url.includes(p))) {
// Render the page to user via SSR (server side rendering)
serverSideRender(req, res, next);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/config/ssr-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ export interface SSRConfig extends Config {
* For improved SSR performance, DSpace defaults this to false (disabled).
*/
inlineCriticalCss: boolean;

/**
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
*/
paths: Array<string>;
}
1 change: 1 addition & 0 deletions src/environments/environment.production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const environment: Partial<BuildConfig> = {
enabled: true,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ],
},
};
1 change: 1 addition & 0 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const environment: BuildConfig = {
enabled: true,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ],
},

// Angular express server settings.
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment: Partial<BuildConfig> = {
enabled: false,
enablePerformanceProfiler: false,
inlineCriticalCss: false,
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/' ],
},
};

Expand Down

0 comments on commit 34c38b6

Please sign in to comment.