mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
[DURACOM-288] Refactoring configuration to transfer state
This commit is contained in:
@@ -273,10 +273,8 @@ function serverSideRender(req, res, sendToUser: boolean = true) {
|
|||||||
}, (err, data) => {
|
}, (err, data) => {
|
||||||
if (hasNoValue(err) && hasValue(data)) {
|
if (hasNoValue(err) && hasValue(data)) {
|
||||||
// Replace REST URL with UI URL
|
// Replace REST URL with UI URL
|
||||||
if (environment.ui.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
|
if (environment.universal.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
|
||||||
const t0 = Date.now();
|
|
||||||
data = data.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
|
data = data.replace(new RegExp(REST_BASE_URL, 'g'), environment.rest.baseUrl);
|
||||||
console.log(`Replaced all SSR URLs in HTML in ${Date.now() - t0}ms`); // todo: remove this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save server side rendered page to cache (if any are enabled)
|
// save server side rendered page to cache (if any are enabled)
|
||||||
|
@@ -48,9 +48,6 @@ export class DefaultAppConfig implements AppConfig {
|
|||||||
|
|
||||||
// Trust X-FORWARDED-* headers from proxies
|
// Trust X-FORWARDED-* headers from proxies
|
||||||
useProxies: true,
|
useProxies: true,
|
||||||
|
|
||||||
transferState: true,
|
|
||||||
replaceRestUrl: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The REST API server settings
|
// The REST API server settings
|
||||||
|
@@ -13,7 +13,4 @@ export class UIServerConfig extends ServerConfig {
|
|||||||
|
|
||||||
// Trust X-FORWARDED-* headers from proxies
|
// Trust X-FORWARDED-* headers from proxies
|
||||||
useProxies: boolean;
|
useProxies: boolean;
|
||||||
|
|
||||||
transferState: boolean;
|
|
||||||
replaceRestUrl: boolean;
|
|
||||||
}
|
}
|
||||||
|
@@ -14,10 +14,29 @@ export interface UniversalConfig extends Config {
|
|||||||
*/
|
*/
|
||||||
inlineCriticalCss?: boolean;
|
inlineCriticalCss?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable state transfer from the server-side application to the client-side application.
|
||||||
|
* Defaults to true.
|
||||||
|
*
|
||||||
|
* Note: When using an external application cache layer, it's recommended not to transfer the state to avoid caching it.
|
||||||
|
* Disabling it ensures that dynamic state information is not inadvertently cached, which can improve security and
|
||||||
|
* ensure that users always use the most up-to-date state.
|
||||||
|
*/
|
||||||
|
transferState: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a different REST base URL is used for the server-side application, the generated state contains references to
|
||||||
|
* REST resources with the internal URL configured, so it is not transferred to the client application, by default.
|
||||||
|
* Enabling this setting transfers the state to the client application and replaces internal URLs with the public
|
||||||
|
* URLs used by the client application.
|
||||||
|
*/
|
||||||
|
replaceRestUrl: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
|
* Paths to enable SSR for. Defaults to the home page and paths in the sitemap.
|
||||||
*/
|
*/
|
||||||
paths: Array<string>;
|
paths: Array<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to enable rendering of search component on SSR
|
* Whether to enable rendering of search component on SSR
|
||||||
*/
|
*/
|
||||||
|
@@ -9,6 +9,8 @@ export const environment: Partial<BuildConfig> = {
|
|||||||
async: true,
|
async: true,
|
||||||
time: false,
|
time: false,
|
||||||
inlineCriticalCss: false,
|
inlineCriticalCss: false,
|
||||||
|
transferState: true,
|
||||||
|
replaceRestUrl: false,
|
||||||
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
||||||
enableSearchComponent: false,
|
enableSearchComponent: false,
|
||||||
enableBrowseComponent: false,
|
enableBrowseComponent: false,
|
||||||
|
@@ -12,6 +12,8 @@ export const environment: BuildConfig = {
|
|||||||
async: true,
|
async: true,
|
||||||
time: false,
|
time: false,
|
||||||
inlineCriticalCss: false,
|
inlineCriticalCss: false,
|
||||||
|
transferState: true,
|
||||||
|
replaceRestUrl: false,
|
||||||
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
||||||
enableSearchComponent: false,
|
enableSearchComponent: false,
|
||||||
enableBrowseComponent: false,
|
enableBrowseComponent: false,
|
||||||
|
@@ -14,6 +14,8 @@ export const environment: Partial<BuildConfig> = {
|
|||||||
async: true,
|
async: true,
|
||||||
time: false,
|
time: false,
|
||||||
inlineCriticalCss: false,
|
inlineCriticalCss: false,
|
||||||
|
transferState: true,
|
||||||
|
replaceRestUrl: false,
|
||||||
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
paths: [ '/home', '/items/', '/entities/', '/collections/', '/communities/', '/bitstream/', '/bitstreams/', '/handle/', '/reload/' ],
|
||||||
enableSearchComponent: false,
|
enableSearchComponent: false,
|
||||||
enableBrowseComponent: false,
|
enableBrowseComponent: false,
|
||||||
|
@@ -35,6 +35,7 @@ import { RootDataService } from '../../app/core/data/root-data.service';
|
|||||||
import { firstValueFrom, lastValueFrom, Subscription } from 'rxjs';
|
import { firstValueFrom, lastValueFrom, Subscription } from 'rxjs';
|
||||||
import { ServerCheckGuard } from '../../app/core/server-check/server-check.guard';
|
import { ServerCheckGuard } from '../../app/core/server-check/server-check.guard';
|
||||||
import { HALEndpointService } from '../../app/core/shared/hal-endpoint.service';
|
import { HALEndpointService } from '../../app/core/shared/hal-endpoint.service';
|
||||||
|
import { BuildConfig } from '../../config/build-config.interface';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs client-side initialization.
|
* Performs client-side initialization.
|
||||||
@@ -48,7 +49,7 @@ export class BrowserInitService extends InitService {
|
|||||||
protected store: Store<AppState>,
|
protected store: Store<AppState>,
|
||||||
protected correlationIdService: CorrelationIdService,
|
protected correlationIdService: CorrelationIdService,
|
||||||
protected transferState: TransferState,
|
protected transferState: TransferState,
|
||||||
@Inject(APP_CONFIG) protected appConfig: AppConfig,
|
@Inject(APP_CONFIG) protected appConfig: BuildConfig,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected localeService: LocaleService,
|
protected localeService: LocaleService,
|
||||||
protected angulartics2DSpace: Angulartics2DSpace,
|
protected angulartics2DSpace: Angulartics2DSpace,
|
||||||
@@ -90,9 +91,7 @@ export class BrowserInitService extends InitService {
|
|||||||
|
|
||||||
protected init(): () => Promise<boolean> {
|
protected init(): () => Promise<boolean> {
|
||||||
return async () => {
|
return async () => {
|
||||||
if (this.appConfig.ui.transferState) {
|
|
||||||
await this.loadAppState();
|
await this.loadAppState();
|
||||||
}
|
|
||||||
this.checkAuthenticationToken();
|
this.checkAuthenticationToken();
|
||||||
this.externalAuthCheck();
|
this.externalAuthCheck();
|
||||||
this.initCorrelationId();
|
this.initCorrelationId();
|
||||||
@@ -124,7 +123,7 @@ export class BrowserInitService extends InitService {
|
|||||||
*/
|
*/
|
||||||
private async loadAppState(): Promise<boolean> {
|
private async loadAppState(): Promise<boolean> {
|
||||||
// The app state can be transferred only when SSR and CSR are using the same base url for the REST API
|
// The app state can be transferred only when SSR and CSR are using the same base url for the REST API
|
||||||
if (this.appConfig.ui.transferState && (!this.appConfig.rest.hasSsrBaseUrl || this.appConfig.ui.replaceRestUrl)) {
|
if (this.appConfig.universal.transferState) {
|
||||||
const state = this.transferState.get<any>(InitService.NGRX_STATE, null);
|
const state = this.transferState.get<any>(InitService.NGRX_STATE, null);
|
||||||
this.transferState.remove(InitService.NGRX_STATE);
|
this.transferState.remove(InitService.NGRX_STATE);
|
||||||
this.store.dispatch(new StoreAction(StoreActionTypes.REHYDRATE, state));
|
this.store.dispatch(new StoreAction(StoreActionTypes.REHYDRATE, state));
|
||||||
|
@@ -21,7 +21,8 @@ import { BreadcrumbsService } from '../../app/breadcrumbs/breadcrumbs.service';
|
|||||||
import { ThemeService } from '../../app/shared/theme-support/theme.service';
|
import { ThemeService } from '../../app/shared/theme-support/theme.service';
|
||||||
import { take } from 'rxjs/operators';
|
import { take } from 'rxjs/operators';
|
||||||
import { MenuService } from '../../app/shared/menu/menu.service';
|
import { MenuService } from '../../app/shared/menu/menu.service';
|
||||||
import { isNotEmpty } from '../../app/shared/empty.util';
|
import { isEmpty, isNotEmpty } from '../../app/shared/empty.util';
|
||||||
|
import { BuildConfig } from '../../config/build-config.interface';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs server-side initialization.
|
* Performs server-side initialization.
|
||||||
@@ -32,7 +33,7 @@ export class ServerInitService extends InitService {
|
|||||||
protected store: Store<AppState>,
|
protected store: Store<AppState>,
|
||||||
protected correlationIdService: CorrelationIdService,
|
protected correlationIdService: CorrelationIdService,
|
||||||
protected transferState: TransferState,
|
protected transferState: TransferState,
|
||||||
@Inject(APP_CONFIG) protected appConfig: AppConfig,
|
@Inject(APP_CONFIG) protected appConfig: BuildConfig,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
protected localeService: LocaleService,
|
protected localeService: LocaleService,
|
||||||
protected angulartics2DSpace: Angulartics2DSpace,
|
protected angulartics2DSpace: Angulartics2DSpace,
|
||||||
@@ -59,9 +60,7 @@ export class ServerInitService extends InitService {
|
|||||||
return async () => {
|
return async () => {
|
||||||
this.checkAuthenticationToken();
|
this.checkAuthenticationToken();
|
||||||
this.saveAppConfigForCSR();
|
this.saveAppConfigForCSR();
|
||||||
if (this.appConfig.ui.transferState) {
|
|
||||||
this.saveAppState();
|
this.saveAppState();
|
||||||
}
|
|
||||||
this.initCorrelationId();
|
this.initCorrelationId();
|
||||||
|
|
||||||
this.checkEnvironment();
|
this.checkEnvironment();
|
||||||
@@ -83,6 +82,7 @@ export class ServerInitService extends InitService {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private saveAppState() {
|
private saveAppState() {
|
||||||
|
if (this.appConfig.universal.transferState && (isEmpty(this.appConfig.rest.ssrBaseUrl) || this.appConfig.universal.replaceRestUrl)) {
|
||||||
this.transferState.onSerialize(InitService.NGRX_STATE, () => {
|
this.transferState.onSerialize(InitService.NGRX_STATE, () => {
|
||||||
let state;
|
let state;
|
||||||
this.store.pipe(take(1)).subscribe((saveState: any) => {
|
this.store.pipe(take(1)).subscribe((saveState: any) => {
|
||||||
@@ -92,6 +92,7 @@ export class ServerInitService extends InitService {
|
|||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private saveAppConfigForCSR(): void {
|
private saveAppConfigForCSR(): void {
|
||||||
if (isNotEmpty(environment.rest.ssrBaseUrl) && environment.rest.baseUrl !== environment.rest.ssrBaseUrl) {
|
if (isNotEmpty(environment.rest.ssrBaseUrl) && environment.rest.baseUrl !== environment.rest.ssrBaseUrl) {
|
||||||
|
Reference in New Issue
Block a user