mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Add configuration to toggle replace/transfer
This commit is contained in:

committed by
Giuseppe Digilio

parent
a3ffda3bf8
commit
f9d8e4e0b7
@@ -272,6 +272,13 @@ function serverSideRender(req, res, sendToUser: boolean = true) {
|
|||||||
requestUrl: req.originalUrl,
|
requestUrl: req.originalUrl,
|
||||||
}, (err, data) => {
|
}, (err, data) => {
|
||||||
if (hasNoValue(err) && hasValue(data)) {
|
if (hasNoValue(err) && hasValue(data)) {
|
||||||
|
// Replace REST URL with UI URL
|
||||||
|
if (environment.ui.replaceRestUrl && REST_BASE_URL !== environment.rest.baseUrl) {
|
||||||
|
const t0 = Date.now();
|
||||||
|
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)
|
||||||
saveToCache(req, data);
|
saveToCache(req, data);
|
||||||
if (sendToUser) {
|
if (sendToUser) {
|
||||||
|
@@ -48,6 +48,9 @@ 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,4 +13,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,9 @@ export class BrowserInitService extends InitService {
|
|||||||
|
|
||||||
protected init(): () => Promise<boolean> {
|
protected init(): () => Promise<boolean> {
|
||||||
return async () => {
|
return async () => {
|
||||||
await this.loadAppState();
|
if (this.appConfig.ui.transferState) {
|
||||||
|
await this.loadAppState();
|
||||||
|
}
|
||||||
this.checkAuthenticationToken();
|
this.checkAuthenticationToken();
|
||||||
this.externalAuthCheck();
|
this.externalAuthCheck();
|
||||||
this.initCorrelationId();
|
this.initCorrelationId();
|
||||||
@@ -122,7 +124,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.rest.hasSsrBaseUrl) {
|
if (this.appConfig.ui.transferState && (!this.appConfig.rest.hasSsrBaseUrl || this.appConfig.ui.replaceRestUrl)) {
|
||||||
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));
|
||||||
|
@@ -59,7 +59,9 @@ export class ServerInitService extends InitService {
|
|||||||
return async () => {
|
return async () => {
|
||||||
this.checkAuthenticationToken();
|
this.checkAuthenticationToken();
|
||||||
this.saveAppConfigForCSR();
|
this.saveAppConfigForCSR();
|
||||||
this.saveAppState();
|
if (this.appConfig.ui.transferState) {
|
||||||
|
this.saveAppState();
|
||||||
|
}
|
||||||
this.initCorrelationId();
|
this.initCorrelationId();
|
||||||
|
|
||||||
this.checkEnvironment();
|
this.checkEnvironment();
|
||||||
|
Reference in New Issue
Block a user