Skip to content

Commit 06f3f8d

Browse files
authored
Merge pull request DSpace#1814 from atmire/issue_1795_issue_1778_fix_config_issues
Repair config issues
2 parents a2f8a5c + 7ca434b commit 06f3f8d

7 files changed

Lines changed: 64 additions & 23 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dspace-angular",
3-
"version": "0.0.0",
3+
"version": "7.4.0-next",
44
"scripts": {
55
"ng": "ng",
66
"config:watch": "nodemon",
@@ -10,7 +10,7 @@
1010
"start:prod": "yarn run build:prod && cross-env NODE_ENV=production yarn run serve:ssr",
1111
"start:mirador:prod": "yarn run build:mirador && yarn run start:prod",
1212
"preserve": "yarn base-href",
13-
"serve": "ng serve --configuration development",
13+
"serve": "ts-node --project ./tsconfig.ts-node.json scripts/serve.ts",
1414
"serve:ssr": "node dist/server/main",
1515
"analyze": "webpack-bundle-analyzer dist/browser/stats.json",
1616
"build": "ng build --configuration development",

scripts/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ const appConfig: AppConfig = buildAppConfig();
1010
* Any CLI arguments given to this script are patched through to `ng serve` as well.
1111
*/
1212
child.spawn(
13-
`ng serve --host ${appConfig.ui.host} --port ${appConfig.ui.port} --serve-path ${appConfig.ui.nameSpace} --ssl ${appConfig.ui.ssl} ${process.argv.slice(2).join(' ')}`,
13+
`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`,
1414
{ stdio: 'inherit', shell: true }
1515
);

server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { ServerAppModule } from './src/main.server';
4848
import { buildAppConfig } from './src/config/config.server';
4949
import { APP_CONFIG, AppConfig } from './src/config/app-config.interface';
5050
import { extendEnvironmentWithAppConfig } from './src/config/config.util';
51+
import { logStartupMessage } from './startup-message';
5152

5253
/*
5354
* Set path for the browser application's dist folder
@@ -281,6 +282,8 @@ function run() {
281282
}
282283

283284
function start() {
285+
logStartupMessage(environment);
286+
284287
/*
285288
* If SSL is enabled
286289
* - Read credentials from configuration files

src/app/init.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ export abstract class InitService {
143143
if (environment.debug) {
144144
console.info(environment);
145145
}
146-
147-
const env: string = environment.production ? 'Production' : 'Development';
148-
const color: string = environment.production ? 'red' : 'green';
149-
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
150146
}
151147

152148
/**

src/config/config.server.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,28 @@ const getEnvironment = (): Environment => {
5454
return environment;
5555
};
5656

57-
const getLocalConfigPath = (env: Environment) => {
57+
/**
58+
* Get the path of the default config file.
59+
*/
60+
const getDefaultConfigPath = () => {
61+
5862
// default to config/config.yml
59-
let localConfigPath = join(CONFIG_PATH, 'config.yml');
63+
let defaultConfigPath = join(CONFIG_PATH, 'config.yml');
6064

61-
if (!fs.existsSync(localConfigPath)) {
62-
localConfigPath = join(CONFIG_PATH, 'config.yaml');
65+
if (!fs.existsSync(defaultConfigPath)) {
66+
defaultConfigPath = join(CONFIG_PATH, 'config.yaml');
6367
}
6468

69+
return defaultConfigPath;
70+
};
71+
72+
/**
73+
* Get the path of an environment-specific config file.
74+
*
75+
* @param env the environment to get the config file for
76+
*/
77+
const getEnvConfigFilePath = (env: Environment) => {
78+
6579
// determine app config filename variations
6680
let envVariations;
6781
switch (env) {
@@ -76,22 +90,21 @@ const getLocalConfigPath = (env: Environment) => {
7690
envVariations = ['dev', 'development'];
7791
}
7892

93+
let envLocalConfigPath;
94+
7995
// check if any environment variations of app config exist
8096
for (const envVariation of envVariations) {
81-
let envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`);
97+
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yml`);
98+
if (fs.existsSync(envLocalConfigPath)) {
99+
break;
100+
}
101+
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
82102
if (fs.existsSync(envLocalConfigPath)) {
83-
localConfigPath = envLocalConfigPath;
84103
break;
85-
} else {
86-
envLocalConfigPath = join(CONFIG_PATH, `config.${envVariation}.yaml`);
87-
if (fs.existsSync(envLocalConfigPath)) {
88-
localConfigPath = envLocalConfigPath;
89-
break;
90-
}
91104
}
92105
}
93106

94-
return localConfigPath;
107+
return envLocalConfigPath;
95108
};
96109

97110
const overrideWithConfig = (config: Config, pathToConfig: string) => {
@@ -174,12 +187,20 @@ export const buildAppConfig = (destConfigPath?: string): AppConfig => {
174187
console.log(`Building ${colors.green.bold(`development`)} app config`);
175188
}
176189

177-
// override with dist config
178-
const localConfigPath = getLocalConfigPath(env);
190+
// override with default config
191+
const defaultConfigPath = getDefaultConfigPath();
192+
if (fs.existsSync(defaultConfigPath)) {
193+
overrideWithConfig(appConfig, defaultConfigPath);
194+
} else {
195+
console.warn(`Unable to find default config file at ${defaultConfigPath}`);
196+
}
197+
198+
// override with env config
199+
const localConfigPath = getEnvConfigFilePath(env);
179200
if (fs.existsSync(localConfigPath)) {
180201
overrideWithConfig(appConfig, localConfigPath);
181202
} else {
182-
console.warn(`Unable to find dist config file at ${localConfigPath}`);
203+
console.warn(`Unable to find env config file at ${localConfigPath}`);
183204
}
184205

185206
// override with external config if specified by environment variable `DSPACE_APP_CONFIG_PATH`

src/modules/app/browser-init.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { StoreAction, StoreActionTypes } from '../../app/store.actions';
2828
import { coreSelector } from '../../app/core/core.selectors';
2929
import { find, map } from 'rxjs/operators';
3030
import { isNotEmpty } from '../../app/shared/empty.util';
31+
import { logStartupMessage } from '../../../startup-message';
3132

3233
/**
3334
* Performs client-side initialization.
@@ -79,6 +80,7 @@ export class BrowserInitService extends InitService {
7980
this.initCorrelationId();
8081

8182
this.checkEnvironment();
83+
logStartupMessage(environment);
8284

8385
this.initI18n();
8486
this.initAngulartics();

startup-message.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import PACKAGE_JSON from './package.json';
2+
import { BuildConfig } from './src/config/build-config.interface';
3+
4+
/**
5+
* Log a message at the start of the application containing the version number and the environment.
6+
*
7+
* @param environment the environment configuration
8+
*/
9+
export const logStartupMessage = (environment: Partial<BuildConfig>) => {
10+
const env: string = environment.production ? 'Production' : 'Development';
11+
const color: string = environment.production ? 'red' : 'green';
12+
13+
console.info('');
14+
console.info(`%cdspace-angular`, `font-weight: bold;`);
15+
console.info(`Version: %c${PACKAGE_JSON.version}`, `font-weight: bold;`);
16+
console.info(`Environment: %c${env}`, `color: ${color}; font-weight: bold;`);
17+
console.info('');
18+
19+
}

0 commit comments

Comments
 (0)