Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
import { extendEnvironmentWithAppConfig } from './src/config/config.util';
import { logStartupMessage } from './startup-message';
import { TOKENITEM } from 'src/app/core/auth/models/auth-token-info.model';
import { SsrExcludePatterns } from './src/config/universal-config.interface';


/*
Expand Down Expand Up @@ -228,7 +229,7 @@ export function app() {
* The callback function to serve server side angular
*/
function ngApp(req, res) {
if (environment.universal.preboot) {
if (environment.universal.preboot && req.method === 'GET' && (req.path === '/' || !isExcludedFromSsr(req.path, environment.universal.excludePathPatterns))) {
// Render the page to user via SSR (server side rendering)
serverSideRender(req, res);
} else {
Expand Down Expand Up @@ -545,6 +546,21 @@ function start() {
}
}

/**
* Check if SSR should be skipped for path
*
* @param path
* @param excludePathPattern
*/
function isExcludedFromSsr(path: string, excludePathPattern: SsrExcludePatterns[]): boolean {
const patterns = excludePathPattern.map(p =>
new RegExp(p.pattern, p.flag || '')
);
return patterns.some((regex) => {
return regex.test(path)
});
}

/*
* The callback function to serve health check requests
*/
Expand Down
10 changes: 10 additions & 0 deletions src/config/universal-config.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { Config } from './config.interface';

export interface SsrExcludePatterns {
pattern: string | RegExp;
flag?: string;
}

export interface UniversalConfig extends Config {
preboot: boolean;
async: boolean;
time: boolean;

/**
* Patterns to be used as regexes to match url's path and check if SSR is disabled for it.
*/
excludePathPatterns: SsrExcludePatterns[];
}
21 changes: 20 additions & 1 deletion src/environments/environment.production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ export const environment: Partial<BuildConfig> = {
universal: {
preboot: true,
async: true,
time: false
time: false,
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: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
],
}
};
21 changes: 20 additions & 1 deletion src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@ export const environment: BuildConfig = {
universal: {
preboot: true,
async: true,
time: false
time: false,
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: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
],
},

// Angular Universal server settings.
Expand Down
21 changes: 20 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@ export const environment: Partial<BuildConfig> = {
universal: {
preboot: false,
async: true,
time: false
time: false,
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: '^/statistics/?' },
{ pattern: '^/admin/' },
{ pattern: '^/processes/?' },
{ pattern: '^/notifications/' },
{ pattern: '^/access-control/' },
{ pattern: '^/health$' },
],
},

// The REST API server settings.
Expand Down
Loading