mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Cleanup and minore refactor.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
// The REST API Location.
|
// The REST API server settings.
|
||||||
"rest": {
|
"rest": {
|
||||||
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
|
// NOTE: Space is capitalized because 'namespace' is a reserved string in TypeScript
|
||||||
"nameSpace": "/api",
|
"nameSpace": "/api",
|
||||||
@@ -7,7 +7,7 @@ module.exports = {
|
|||||||
"address": "localhost",
|
"address": "localhost",
|
||||||
"port": 3000
|
"port": 3000
|
||||||
},
|
},
|
||||||
// Protocol, path and port in use for this Angular2 UI
|
// Angular2 UI server settings.
|
||||||
"ui": {
|
"ui": {
|
||||||
"nameSpace": "/",
|
"nameSpace": "/",
|
||||||
"protocol": "http",
|
"protocol": "http",
|
||||||
@@ -16,10 +16,11 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
"cache": {
|
"cache": {
|
||||||
// how long should objects be cached for by default
|
// how long should objects be cached for by default
|
||||||
"msToLive": 1 * 60 * 1000, // 1 minute
|
"msToLive": 15 * 60 * 1000, // 15 minute
|
||||||
|
"control": "max-age=60" // revalidate browser
|
||||||
},
|
},
|
||||||
"universal": {
|
"universal": {
|
||||||
// universal settings
|
// Angular Universal settings
|
||||||
"preboot": true,
|
"preboot": true,
|
||||||
"async": true
|
"async": true
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
// Sticky Footer
|
// Sticky Footer
|
||||||
|
|
||||||
.outer-wrapper {
|
.outer-wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@@ -21,7 +21,7 @@ export abstract class DataEffects<T extends CacheableObject> {
|
|||||||
protected abstract getSerializer(): Serializer<T>;
|
protected abstract getSerializer(): Serializer<T>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private config: GlobalConfig,
|
private EnvConfig: GlobalConfig,
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private restApi: DSpaceRESTv2Service,
|
private restApi: DSpaceRESTv2Service,
|
||||||
private objectCache: ObjectCacheService,
|
private objectCache: ObjectCacheService,
|
||||||
@@ -41,11 +41,11 @@ export abstract class DataEffects<T extends CacheableObject> {
|
|||||||
if (hasNoValue(t) || hasNoValue(t.uuid)) {
|
if (hasNoValue(t) || hasNoValue(t.uuid)) {
|
||||||
throw new Error('The server returned an invalid object');
|
throw new Error('The server returned an invalid object');
|
||||||
}
|
}
|
||||||
this.objectCache.add(t, this.config.cache.msToLive);
|
this.objectCache.add(t, this.EnvConfig.cache.msToLive);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.map((ts: Array<T>) => ts.map(t => t.uuid))
|
.map((ts: Array<T>) => ts.map(t => t.uuid))
|
||||||
.map((ids: Array<string>) => new RequestCacheSuccessAction(action.payload.key, ids, new Date().getTime(), this.config.cache.msToLive))
|
.map((ids: Array<string>) => new RequestCacheSuccessAction(action.payload.key, ids, new Date().getTime(), this.EnvConfig.cache.msToLive))
|
||||||
.catch((error: Error) => Observable.of(new RequestCacheErrorAction(action.payload.key, error.message)));
|
.catch((error: Error) => Observable.of(new RequestCacheErrorAction(action.payload.key, error.message)));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,9 +59,9 @@ export abstract class DataEffects<T extends CacheableObject> {
|
|||||||
if (hasNoValue(t) || hasNoValue(t.uuid)) {
|
if (hasNoValue(t) || hasNoValue(t.uuid)) {
|
||||||
throw new Error('The server returned an invalid object');
|
throw new Error('The server returned an invalid object');
|
||||||
}
|
}
|
||||||
this.objectCache.add(t, this.config.cache.msToLive);
|
this.objectCache.add(t, this.EnvConfig.cache.msToLive);
|
||||||
})
|
})
|
||||||
.map((t: T) => new RequestCacheSuccessAction(action.payload.key, [t.uuid], new Date().getTime(), this.config.cache.msToLive))
|
.map((t: T) => new RequestCacheSuccessAction(action.payload.key, [t.uuid], new Date().getTime(), this.EnvConfig.cache.msToLive))
|
||||||
.catch((error: Error) => Observable.of(new RequestCacheErrorAction(action.payload.key, error.message)));
|
.catch((error: Error) => Observable.of(new RequestCacheErrorAction(action.payload.key, error.message)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -15,9 +15,9 @@ interface GlobalConfig {
|
|||||||
"ui": ServerConfig,
|
"ui": ServerConfig,
|
||||||
"cache": {
|
"cache": {
|
||||||
"msToLive": number,
|
"msToLive": number,
|
||||||
|
"control": string
|
||||||
},
|
},
|
||||||
"universal": {
|
"universal": {
|
||||||
"shouldRehydrate": boolean,
|
|
||||||
"preboot": boolean,
|
"preboot": boolean,
|
||||||
"async": boolean
|
"async": boolean
|
||||||
}
|
}
|
||||||
@@ -56,9 +56,9 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if EnvConfigFile set try to get configs
|
// if EnvConfigFile set try to get configs
|
||||||
if(EnvConfigFile) {
|
if (EnvConfigFile) {
|
||||||
try {
|
try {
|
||||||
EnvConfig = <GlobalConfig> Object.assign(EnvConfig, configContext(EnvConfigFile));
|
EnvConfig = <GlobalConfig>Object.assign(EnvConfig, configContext(EnvConfigFile));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Cannot find file " + EnvConfigFile);
|
console.warn("Cannot find file " + EnvConfigFile);
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ import { effects } from '../../app/app.effects';
|
|||||||
import { Meta } from '../angular2-meta';
|
import { Meta } from '../angular2-meta';
|
||||||
import { RehydrateStoreAction } from "../../app/store.actions";
|
import { RehydrateStoreAction } from "../../app/store.actions";
|
||||||
|
|
||||||
import { GLOBAL_CONFIG, EnvConfig } from '../../config';
|
import { GLOBAL_CONFIG, GlobalConfig, EnvConfig } from '../../config';
|
||||||
|
|
||||||
// import * as LRU from 'modern-lru';
|
// import * as LRU from 'modern-lru';
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ export const UNIVERSAL_KEY = 'UNIVERSAL_CACHE';
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class MainModule {
|
export class MainModule {
|
||||||
constructor(public store: Store<AppState>) {
|
constructor( @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig, public store: Store<AppState>) {
|
||||||
// TODO(gdi2290): refactor into a lifecycle hook
|
// TODO(gdi2290): refactor into a lifecycle hook
|
||||||
this.doRehydrate();
|
this.doRehydrate();
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,9 @@ export class MainModule {
|
|||||||
doRehydrate() {
|
doRehydrate() {
|
||||||
let defaultValue = {};
|
let defaultValue = {};
|
||||||
let serverCache = this._getCacheValue(NGRX_CACHE_KEY, defaultValue);
|
let serverCache = this._getCacheValue(NGRX_CACHE_KEY, defaultValue);
|
||||||
this.store.dispatch(new RehydrateStoreAction(serverCache));
|
if (this.EnvConfig.universal.preboot) {
|
||||||
|
this.store.dispatch(new RehydrateStoreAction(serverCache));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_getCacheValue(key: string, defaultValue: any): any {
|
_getCacheValue(key: string, defaultValue: any): any {
|
||||||
|
@@ -64,7 +64,7 @@ app.use(morgan('common', {
|
|||||||
|
|
||||||
function cacheControl(req, res, next) {
|
function cacheControl(req, res, next) {
|
||||||
// instruct browser to revalidate in 60 seconds
|
// instruct browser to revalidate in 60 seconds
|
||||||
res.header('Cache-Control', 'max-age=60');
|
res.header('Cache-Control', EnvConfig.cache.control || 'max-age=60');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ routes.forEach(route => {
|
|||||||
app.get(`/${route}/*`, ngApp);
|
app.get(`/${route}/*`, ngApp);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('*', function(req, res) {
|
app.get('*', function (req, res) {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
var pojo = { status: 404, message: 'No Content' };
|
var pojo = { status: 404, message: 'No Content' };
|
||||||
var json = JSON.stringify(pojo, null, 2);
|
var json = JSON.stringify(pojo, null, 2);
|
||||||
|
@@ -57,7 +57,7 @@ app.use(morgan('dev'));
|
|||||||
|
|
||||||
function cacheControl(req, res, next) {
|
function cacheControl(req, res, next) {
|
||||||
// instruct browser to revalidate in 60 seconds
|
// instruct browser to revalidate in 60 seconds
|
||||||
res.header('Cache-Control', 'max-age=60');
|
res.header('Cache-Control', EnvConfig.cache.control || 'max-age=60');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ routes.forEach(route => {
|
|||||||
app.get(`/${route}/*`, ngApp);
|
app.get(`/${route}/*`, ngApp);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('*', function(req, res) {
|
app.get('*', function (req, res) {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
var pojo = { status: 404, message: 'No Content' };
|
var pojo = { status: 404, message: 'No Content' };
|
||||||
var json = JSON.stringify(pojo, null, 2);
|
var json = JSON.stringify(pojo, null, 2);
|
||||||
|
Reference in New Issue
Block a user