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.
  • Loading branch information
alanorth committed Nov 22, 2024
1 parent 757d23e commit 3d544f6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ const cookieParser = require('cookie-parser');

const appConfig: AppConfig = buildAppConfig(join(DIST_FOLDER, 'assets/config.json'));

// only enable SSR for paths in the sitemap
const SSR_PATHS = [
'/items/',
'/entities/',
'/collections/',
'/communities/',
'/bitstream/',
'/bitstreams/'
];

// cache of SSR pages for known bots, only enabled in production mode
let botCache: LRU<string, any>;

Expand Down Expand Up @@ -218,7 +228,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' && 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

0 comments on commit 3d544f6

Please sign in to comment.