mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Merge pull request #1814 from atmire/issue_1795_issue_1778_fix_config_issues
Repair config issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dspace-angular",
|
"name": "dspace-angular",
|
||||||
"version": "0.0.0",
|
"version": "7.4.0-next",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"config:watch": "nodemon",
|
"config:watch": "nodemon",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"start:prod": "yarn run build:prod && cross-env NODE_ENV=production yarn run serve:ssr",
|
"start:prod": "yarn run build:prod && cross-env NODE_ENV=production yarn run serve:ssr",
|
||||||
"start:mirador:prod": "yarn run build:mirador && yarn run start:prod",
|
"start:mirador:prod": "yarn run build:mirador && yarn run start:prod",
|
||||||
"preserve": "yarn base-href",
|
"preserve": "yarn base-href",
|
||||||
"serve": "ng serve --configuration development",
|
"serve": "ts-node --project ./tsconfig.ts-node.json scripts/serve.ts",
|
||||||
"serve:ssr": "node dist/server/main",
|
"serve:ssr": "node dist/server/main",
|
||||||
"analyze": "webpack-bundle-analyzer dist/browser/stats.json",
|
"analyze": "webpack-bundle-analyzer dist/browser/stats.json",
|
||||||
"build": "ng build --configuration development",
|
"build": "ng build --configuration development",
|
||||||
|
@@ -10,6 +10,6 @@ const appConfig: AppConfig = buildAppConfig();
|
|||||||
* Any CLI arguments given to this script are patched through to `ng serve` as well.
|
* Any CLI arguments given to this script are patched through to `ng serve` as well.
|
||||||
*/
|
*/
|
||||||
child.spawn(
|
child.spawn(
|
||||||
`ng serve --host ${appConfig.ui.host} --port ${appConfig.ui.port} --serve-path ${appConfig.ui.nameSpace} --ssl ${appConfig.ui.ssl} ${process.argv.slice(2).join(' ')}`,
|
`ng serve --host ${appConfig.ui.host} --port ${appConfig.ui.port} --serve-path ${appConfig.ui.nameSpace} --ssl ${appConfig.ui.ssl} ${process.argv.slice(2).join(' ')} --configuration development`,
|
||||||
{ stdio: 'inherit', shell: true }
|
{ stdio: 'inherit', shell: true }
|
||||||
);
|
);
|
||||||
|
@@ -48,6 +48,7 @@ import { ServerAppModule } from './src/main.server';
|
|||||||
import { buildAppConfig } from './src/config/config.server';
|
import { buildAppConfig } from './src/config/config.server';
|
||||||
import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
|
import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
|
||||||
import { extendEnvironmentWithAppConfig } from './src/config/config.util';
|
import { extendEnvironmentWithAppConfig } from './src/config/config.util';
|
||||||
|
import { logStartupMessage } from './startup-message';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set path for the browser application's dist folder
|
* Set path for the browser application's dist folder
|
||||||
@@ -281,6 +282,8 @@ function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
|
logStartupMessage(environment);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If SSL is enabled
|
* If SSL is enabled
|
||||||
* - Read credentials from configuration files
|
* - Read credentials from configuration files
|
||||||
|
@@ -143,10 +143,6 @@ export abstract class InitService {
|
|||||||
if (environment.debug) {
|
if (environment.debug) {
|
||||||
console.info(environment);
|
console.info(environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
const env: string = environment.production ? 'Production' : 'Development';
|
|
||||||
const color: string = environment.production ? 'red' : 'green';
|
|
||||||
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -54,14 +54,28 @@ const getEnvironment = (): Environment => {
|
|||||||
return environment;
|
return environment;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLocalConfigPath = (env: Environment) => {
|
/**
|
||||||
// default to config/config.yml
|
* Get the path of the default config file.
|
||||||
let localConfigPath = join(CONFIG_PATH, 'config.yml');
|
*/
|
||||||
|
const getDefaultConfigPath = () => {
|
||||||
|
|
||||||
if (!fs.existsSync(localConfigPath)) {
|
// default to config/config.yml
|
||||||
localConfigPath = join(CONFIG_PATH, 'config.yaml');
|
let defaultConfigPath = join(CONFIG_PATH, 'config.yml');
|
||||||
|
|
||||||
|
if (!fs.existsSync(defaultConfigPath)) {
|
||||||
|
defaultConfigPath = join(CONFIG_PATH, 'config.yaml');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultConfigPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path of an environment-specific config file.
|
||||||
|
*
|
||||||
|
* @param env the environment to get the config file for
|
||||||
|
*/
|
||||||
|
const getEnvConfigFilePath = (env: Environment) => {
|
||||||
|
|
||||||
// determine app config filename variations
|
// determine app config filename variations
|
||||||
let envVariations;
|
let envVariations;
|
||||||
switch (env) {
|
switch (env) {
|
||||||
@@ -76,22 +90,21 @@ const getLocalConfigPath = (env: Environment) => {
|
|||||||
envVariations = ['dev', 'development'];
|
envVariations = ['dev', 'development'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let envLocalConfigPath;
|
||||||
|
|
||||||
// check if any environment variations of app config exist
|
// check if any environment variations of app config exist
|
||||||
for (const envVariation of envVariations) {
|
for (const envVariation of envVariations) {
|
||||||
let envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`);
|
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`);
|
||||||
|
if (fs.existsSync(envLocalConfigPath)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
|
||||||
if (fs.existsSync(envLocalConfigPath)) {
|
if (fs.existsSync(envLocalConfigPath)) {
|
||||||
localConfigPath = envLocalConfigPath;
|
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
|
|
||||||
if (fs.existsSync(envLocalConfigPath)) {
|
|
||||||
localConfigPath = envLocalConfigPath;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return localConfigPath;
|
return envLocalConfigPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
const overrideWithConfig = (config: Config, pathToConfig: string) => {
|
const overrideWithConfig = (config: Config, pathToConfig: string) => {
|
||||||
@@ -174,12 +187,20 @@ export const buildAppConfig = (destConfigPath?: string): AppConfig => {
|
|||||||
console.log(`Building ${colors.green.bold(`development`)} app config`);
|
console.log(`Building ${colors.green.bold(`development`)} app config`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// override with dist config
|
// override with default config
|
||||||
const localConfigPath = getLocalConfigPath(env);
|
const defaultConfigPath = getDefaultConfigPath();
|
||||||
|
if (fs.existsSync(defaultConfigPath)) {
|
||||||
|
overrideWithConfig(appConfig, defaultConfigPath);
|
||||||
|
} else {
|
||||||
|
console.warn(`Unable to find default config file at ${defaultConfigPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// override with env config
|
||||||
|
const localConfigPath = getEnvConfigFilePath(env);
|
||||||
if (fs.existsSync(localConfigPath)) {
|
if (fs.existsSync(localConfigPath)) {
|
||||||
overrideWithConfig(appConfig, localConfigPath);
|
overrideWithConfig(appConfig, localConfigPath);
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Unable to find dist config file at ${localConfigPath}`);
|
console.warn(`Unable to find env config file at ${localConfigPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH`
|
// override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH`
|
||||||
|
@@ -28,6 +28,7 @@ import { StoreAction, StoreActionTypes } from '../../app/store.actions';
|
|||||||
import { coreSelector } from '../../app/core/core.selectors';
|
import { coreSelector } from '../../app/core/core.selectors';
|
||||||
import { find, map } from 'rxjs/operators';
|
import { find, map } from 'rxjs/operators';
|
||||||
import { isNotEmpty } from '../../app/shared/empty.util';
|
import { isNotEmpty } from '../../app/shared/empty.util';
|
||||||
|
import { logStartupMessage } from '../../../startup-message';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs client-side initialization.
|
* Performs client-side initialization.
|
||||||
@@ -79,6 +80,7 @@ export class BrowserInitService extends InitService {
|
|||||||
this.initCorrelationId();
|
this.initCorrelationId();
|
||||||
|
|
||||||
this.checkEnvironment();
|
this.checkEnvironment();
|
||||||
|
logStartupMessage(environment);
|
||||||
|
|
||||||
this.initI18n();
|
this.initI18n();
|
||||||
this.initAngulartics();
|
this.initAngulartics();
|
||||||
|
19
startup-message.ts
Normal file
19
startup-message.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import PACKAGE_JSON from './package.json';
|
||||||
|
import { BuildConfig } from './src/config/build-config.interface';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a message at the start of the application containing the version number and the environment.
|
||||||
|
*
|
||||||
|
* @param environment the environment configuration
|
||||||
|
*/
|
||||||
|
export const logStartupMessage = (environment: Partial<BuildConfig>) => {
|
||||||
|
const env: string = environment.production ? 'Production' : 'Development';
|
||||||
|
const color: string = environment.production ? 'red' : 'green';
|
||||||
|
|
||||||
|
console.info('');
|
||||||
|
console.info(`%cdspace-angular`, `font-weight: bold;`);
|
||||||
|
console.info(`Version: %c${PACKAGE_JSON.version}`, `font-weight: bold;`);
|
||||||
|
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
|
||||||
|
console.info('');
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user