[ADF-967] evaluate "hostname" and "port" for string settings (#2040)

* evaluate 'hostname' and 'port' in app config strings

* update unit tests

* fix unit tests

* fix unit tests

* update readme
This commit is contained in:
Denys Vuika
2017-07-04 10:04:58 +01:00
committed by Eugenio Romano
parent ff2c566c90
commit 40fe3ce361
14 changed files with 72 additions and 33 deletions

View File

@@ -23,8 +23,8 @@ import { ObjectUtils } from '../utils/object-utils';
export class AppConfigService {
private config: any = {
'ecmHost': 'http://localhost:3000/ecm',
'bpmHost': 'http://localhost:3000/bpm',
'ecmHost': 'http://{hostname}:{port}/ecm',
'bpmHost': 'http://{hostname}:{port}/bpm',
'application': {
'name': 'Alfresco'
}
@@ -35,7 +35,14 @@ export class AppConfigService {
constructor(private http: Http) {}
get<T>(key: string): T {
return <T> ObjectUtils.getValue(this.config, key);
let result: any = ObjectUtils.getValue(this.config, key);
if (typeof result === 'string') {
const map = new Map<string, string>();
map.set('hostname', location.hostname);
map.set('port', location.port);
result = this.formatString(result, map);
}
return <T> result;
}
load(resource: string = 'app.config.json'): Promise<any> {
@@ -54,6 +61,17 @@ export class AppConfigService {
);
});
}
private formatString(str: string, map: Map<string, string>): string {
let result = str;
map.forEach((value, key) => {
const expr = new RegExp('{' + key + '}', 'gm');
result = result.replace(expr, value);
});
return result;
}
}
export function InitAppConfigServiceProvider(resource: string): any {