optional port number (#2518)

This commit is contained in:
Denys Vuika 2017-10-20 16:41:19 +01:00 committed by Eugenio Romano
parent c2cafaa648
commit f9fc76a3ce
2 changed files with 40 additions and 4 deletions

View File

@ -62,6 +62,33 @@ describe('AppConfigService', () => {
expect(service).toBeDefined();
});
it('should skip the optional port number', () => {
appConfigService.config.testUrl = 'http://{hostname}{:port}';
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue('');
expect(appConfigService.get('testUrl')).toBe('http://localhost');
});
it('should set the optional port number', () => {
appConfigService.config.testUrl = 'http://{hostname}{:port}';
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue(':9090');
expect(appConfigService.get('testUrl')).toBe('http://localhost:9090');
});
it('should set the mandatory port number', () => {
appConfigService.config.testUrl = 'http://{hostname}:{port}';
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue('9090');
expect(appConfigService.get('testUrl')).toBe('http://localhost:9090');
});
it('should load external settings', () => {
appConfigService.load().then(config => {
expect(config).toEqual(mockResponse);

View File

@ -28,8 +28,8 @@ export class AppConfigService {
application: {
name: 'Alfresco ADF Application'
},
ecmHost: 'http://{hostname}:{port}/ecm',
bpmHost: 'http://{hostname}:{port}/bpm'
ecmHost: 'http://{hostname}{:port}/ecm',
bpmHost: 'http://{hostname}{:port}/bpm'
};
constructor(private http: Http) {}
@ -38,8 +38,9 @@ export class AppConfigService {
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);
map.set('hostname', this.getLocationHostname());
map.set(':port', this.getLocationPort(':'));
map.set('port', this.getLocationPort());
result = this.formatString(result, map);
}
if (result === undefined) {
@ -48,6 +49,14 @@ export class AppConfigService {
return <T> result;
}
getLocationHostname(): string {
return location.hostname;
}
getLocationPort(prefix: string = ''): string {
return location.port ? prefix + location.port : '';
}
load(): Promise<any> {
return new Promise(resolve => {
this.http.get('app.config.json').subscribe(