From f9fc76a3ce9bca801a7de0d63f174aea9bd384e0 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 20 Oct 2017 16:41:19 +0100 Subject: [PATCH] optional port number (#2518) --- .../src/services/app-config.service.spec.ts | 27 +++++++++++++++++++ .../src/services/app-config.service.ts | 17 +++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts index 079d58648b..350faa6a6b 100644 --- a/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts @@ -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); diff --git a/ng2-components/ng2-alfresco-core/src/services/app-config.service.ts b/ng2-components/ng2-alfresco-core/src/services/app-config.service.ts index 7fa753a236..b56daff617 100644 --- a/ng2-components/ng2-alfresco-core/src/services/app-config.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/app-config.service.ts @@ -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(); - 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 result; } + getLocationHostname(): string { + return location.hostname; + } + + getLocationPort(prefix: string = ''): string { + return location.port ? prefix + location.port : ''; + } + load(): Promise { return new Promise(resolve => { this.http.get('app.config.json').subscribe(