mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 11:33:04 +00:00
fixed environment config, upgraded angular again
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Look in ./config folder for config
|
||||
import { InjectionToken } from '@angular/core';
|
||||
|
||||
import { ServerConfig } from './config/server-config.interface';
|
||||
@@ -5,43 +6,51 @@ import { GlobalConfig } from './config/global-config.interface';
|
||||
|
||||
const GLOBAL_CONFIG: InjectionToken<GlobalConfig> = new InjectionToken<GlobalConfig>('config');
|
||||
|
||||
let configContext = require.context("../config", false, /js$/);
|
||||
|
||||
let production = false;
|
||||
|
||||
let ENV_CONFIG: GlobalConfig;
|
||||
|
||||
let envConfigFile: string;
|
||||
|
||||
// check process.env.NODE_ENV to determine which environment config to use
|
||||
// process.env.NODE_ENV is defined by webpack, else assume development
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'prod':
|
||||
case 'production':
|
||||
// webpack.prod.config.ts defines process.env.NODE_ENV = 'production'
|
||||
envConfigFile = './environment.prod.js';
|
||||
production = true;
|
||||
break;
|
||||
case 'test':
|
||||
// webpack.test.config.ts defines process.env.NODE_ENV = 'test'
|
||||
envConfigFile = './environment.test.js';
|
||||
break;
|
||||
default:
|
||||
// if not using webpack.prod.config.ts or webpack.test.config.ts, it must be development
|
||||
envConfigFile = './environment.dev.js';
|
||||
}
|
||||
|
||||
try {
|
||||
ENV_CONFIG = require('../config/environment.default.js') as GlobalConfig;
|
||||
ENV_CONFIG = configContext('./environment.default.js') as GlobalConfig;
|
||||
} catch (e) {
|
||||
throw new Error('Cannot find file config/environment.default.js');
|
||||
}
|
||||
|
||||
switch (process.env.NODE_ENV) {
|
||||
case 'prod':
|
||||
case 'production':
|
||||
production = true;
|
||||
try {
|
||||
ENV_CONFIG = Object.assign(ENV_CONFIG, require('../config/environment.prod.js')) as GlobalConfig;
|
||||
} catch (e) {
|
||||
console.warn('Cannot find file config/environment.prod.js', 'Using default environment.');
|
||||
}
|
||||
break;
|
||||
case 'test':
|
||||
try {
|
||||
ENV_CONFIG = Object.assign(ENV_CONFIG, require('../config/environment.test.js')) as GlobalConfig;
|
||||
} catch (e) {
|
||||
console.warn('Cannot find file config/environment.test.js', 'Using default environment.');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
ENV_CONFIG = Object.assign(ENV_CONFIG, require('../config/environment.dev.js')) as GlobalConfig;
|
||||
} catch (e) {
|
||||
console.warn('Cannot find file config/environment.dev.js', 'Using default environment.');
|
||||
}
|
||||
// if envConfigFile set try to get configs
|
||||
if (envConfigFile) {
|
||||
try {
|
||||
ENV_CONFIG = configContext(envConfigFile) as GlobalConfig;
|
||||
} catch (e) {
|
||||
console.warn('Cannot find file ' + envConfigFile.substring(2, envConfigFile.length), 'Using default environment.');
|
||||
}
|
||||
}
|
||||
|
||||
// set config for whether running in production
|
||||
ENV_CONFIG.production = production;
|
||||
|
||||
// set base url if property is object with ssl, address, and port. i.e. ServerConfig
|
||||
for (const key in ENV_CONFIG) {
|
||||
if (ENV_CONFIG[key].host) {
|
||||
ENV_CONFIG[key].baseUrl = [
|
||||
|
Reference in New Issue
Block a user