mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +00:00
recursive merge of config
This commit is contained in:
@@ -41,6 +41,10 @@ export class AppComponent implements OnInit {
|
|||||||
translate.setDefaultLang('en');
|
translate.setDefaultLang('en');
|
||||||
// the lang to use, if the lang isn't available, it will use the current loader to get them
|
// the lang to use, if the lang isn't available, it will use the current loader to get them
|
||||||
translate.use('en');
|
translate.use('en');
|
||||||
|
|
||||||
|
if (config.debug) {
|
||||||
|
console.info(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewChecked() {
|
ngAfterViewChecked() {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
// Look in ./config folder for config
|
// Look in ./config folder for config
|
||||||
import { InjectionToken } from '@angular/core';
|
import { InjectionToken } from '@angular/core';
|
||||||
|
|
||||||
|
import { Config } from './config/config.interface';
|
||||||
import { ServerConfig } from './config/server-config.interface';
|
import { ServerConfig } from './config/server-config.interface';
|
||||||
import { GlobalConfig } from './config/global-config.interface';
|
import { GlobalConfig } from './config/global-config.interface';
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ try {
|
|||||||
// if envConfigFile set try to get configs
|
// if envConfigFile set try to get configs
|
||||||
if (envConfigFile) {
|
if (envConfigFile) {
|
||||||
try {
|
try {
|
||||||
ENV_CONFIG = Object.assign(ENV_CONFIG, configContext(envConfigFile)) as GlobalConfig;
|
merge(configContext(envConfigFile) as GlobalConfig);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Cannot find file ' + envConfigFile.substring(2, envConfigFile.length), 'Using default environment.');
|
console.warn('Cannot find file ' + envConfigFile.substring(2, envConfigFile.length), 'Using default environment.');
|
||||||
}
|
}
|
||||||
@@ -50,15 +51,60 @@ if (envConfigFile) {
|
|||||||
// set config for whether running in production
|
// set config for whether running in production
|
||||||
ENV_CONFIG.production = production;
|
ENV_CONFIG.production = production;
|
||||||
|
|
||||||
// set base url if property is object with ssl, address, and port. i.e. ServerConfig
|
function merge(config: GlobalConfig): void {
|
||||||
for (const key in ENV_CONFIG) {
|
innerMerge(ENV_CONFIG, config);
|
||||||
if (ENV_CONFIG[key].host) {
|
buildBaseUrls();
|
||||||
ENV_CONFIG[key].baseUrl = [
|
}
|
||||||
ENV_CONFIG[key].ssl ? 'https://' : 'http://',
|
|
||||||
ENV_CONFIG[key].host,
|
function innerMerge(globalConfig: Config, config: Config): void {
|
||||||
ENV_CONFIG[key].port ? (ENV_CONFIG[key].port !== 80 && ENV_CONFIG[key].port !== 443) ? ':' + ENV_CONFIG[key].port : '' : ''
|
for (const key in config) {
|
||||||
].join('');
|
if (config.hasOwnProperty(key)) {
|
||||||
|
if (isObject(config[key])) {
|
||||||
|
innerMerge(globalConfig[key], config[key]);
|
||||||
|
} else {
|
||||||
|
if (isDefined(config[key])) {
|
||||||
|
globalConfig[key] = config[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildBaseUrls(): void {
|
||||||
|
for (const key in ENV_CONFIG) {
|
||||||
|
if (ENV_CONFIG.hasOwnProperty(key) && ENV_CONFIG[key].host) {
|
||||||
|
ENV_CONFIG[key].baseUrl = [
|
||||||
|
getProtocol(ENV_CONFIG[key].ssl),
|
||||||
|
getHost(ENV_CONFIG[key].host),
|
||||||
|
getPort(ENV_CONFIG[key].port),
|
||||||
|
getContextPath(ENV_CONFIG[key].contextPath)
|
||||||
|
].join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProtocol(ssl: boolean): string {
|
||||||
|
return ssl ? 'https://' : 'http://';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHost(host: string): string {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPort(port: number): string {
|
||||||
|
return port ? (port !== 80 && port !== 443) ? ':' + port : '' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getContextPath(contextPath: string): string {
|
||||||
|
return contextPath ? '/' + contextPath : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function isDefined(value: any): boolean {
|
||||||
|
return typeof value !== 'undefined' && value !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isObject(item: any): boolean {
|
||||||
|
return item && typeof item === 'object' && !Array.isArray(item);
|
||||||
|
}
|
||||||
|
|
||||||
export { GlobalConfig, GLOBAL_CONFIG, ENV_CONFIG }
|
export { GlobalConfig, GLOBAL_CONFIG, ENV_CONFIG }
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
export interface CacheConfig {
|
import { Config } from './config.interface';
|
||||||
|
|
||||||
|
export interface CacheConfig extends Config {
|
||||||
msToLive: number,
|
msToLive: number,
|
||||||
control: string
|
control: string
|
||||||
}
|
}
|
||||||
|
4
src/config/config.interface.ts
Normal file
4
src/config/config.interface.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// tslint:disable-next-line:no-empty-interface
|
||||||
|
export interface Config {
|
||||||
|
|
||||||
|
}
|
@@ -1,8 +1,9 @@
|
|||||||
|
import { Config } from './config.interface';
|
||||||
import { ServerConfig } from './server-config.interface';
|
import { ServerConfig } from './server-config.interface';
|
||||||
import { CacheConfig } from './cache-config.interface';
|
import { CacheConfig } from './cache-config.interface';
|
||||||
import { UniversalConfig } from './universal-config.interface';
|
import { UniversalConfig } from './universal-config.interface';
|
||||||
|
|
||||||
export interface GlobalConfig {
|
export interface GlobalConfig extends Config {
|
||||||
ui: ServerConfig;
|
ui: ServerConfig;
|
||||||
rest: ServerConfig;
|
rest: ServerConfig;
|
||||||
production: boolean;
|
production: boolean;
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
export interface ServerConfig {
|
import { Config } from './config.interface';
|
||||||
|
|
||||||
|
export interface ServerConfig extends Config {
|
||||||
ssl: boolean;
|
ssl: boolean;
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
export interface UniversalConfig {
|
import { Config } from './config.interface';
|
||||||
|
|
||||||
|
export interface UniversalConfig extends Config {
|
||||||
preboot: boolean,
|
preboot: boolean,
|
||||||
async: boolean,
|
async: boolean,
|
||||||
time: boolean
|
time: boolean
|
||||||
|
Reference in New Issue
Block a user