From db7d0b7c0824f7d9e23f47d8a66d3219f2926c53 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 15 May 2018 13:10:27 +0100 Subject: [PATCH] [ADF-2961] support for protocol substition in app config files (#3324) * support for protocol substition in app config files * Update app-config.service.spec.ts * Update app-config.service.spec.ts --- docs/core/app-config.service.md | 5 +++-- lib/core/app-config/app-config.service.spec.ts | 12 ++++++++++++ lib/core/app-config/app-config.service.ts | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/core/app-config.service.md b/docs/core/app-config.service.md index 560a679530..dad078868a 100644 --- a/docs/core/app-config.service.md +++ b/docs/core/app-config.service.md @@ -109,8 +109,8 @@ The `AppConfigService` also supports a limited set of variable substitutions to ```json { - "ecmHost": "http://{hostname}:{port}/ecm", - "bpmHost": "http://{hostname}:{port}/bpm", + "ecmHost": "{protocol}//{hostname}:{port}/ecm", + "bpmHost": "{protocol}//{hostname}:{port}/bpm", "application": { "name": "Alfresco" } @@ -121,6 +121,7 @@ The supported variables are: | Variable name | Runtime value | | ------------- | ------------- | +| protocol | `location.protocol` | | hostname | `location.hostname` | | port | `location.port` | diff --git a/lib/core/app-config/app-config.service.spec.ts b/lib/core/app-config/app-config.service.spec.ts index 17af4a76e6..31130d8bb8 100644 --- a/lib/core/app-config/app-config.service.spec.ts +++ b/lib/core/app-config/app-config.service.spec.ts @@ -113,6 +113,18 @@ describe('AppConfigService', () => { expect(appConfigService.get('testUrl')).toBe('http://localhost:9090'); }); + it('should use protocol value', () => { + spyOn(appConfigService, 'getLocationPort').and.returnValue('9090'); + const protocolSpy = spyOn(appConfigService, 'getLocationProtocol'); + appConfigService.config.testUrl = '{protocol}//{hostname}:{port}'; + + protocolSpy.and.returnValue('https:'); + expect(appConfigService.get('testUrl')).toBe('https://localhost:9090'); + + protocolSpy.and.returnValue('ftp:'); + expect(appConfigService.get('testUrl')).toBe('ftp://localhost:9090'); + }); + it('should load external settings', () => { appConfigService.load().then(config => { expect(config).toEqual(mockResponse); diff --git a/lib/core/app-config/app-config.service.ts b/lib/core/app-config/app-config.service.ts index 7b5a243a63..a4ea991def 100644 --- a/lib/core/app-config/app-config.service.ts +++ b/lib/core/app-config/app-config.service.ts @@ -66,6 +66,7 @@ export class AppConfigService { map.set('hostname', this.getLocationHostname()); map.set(':port', this.getLocationPort(':')); map.set('port', this.getLocationPort()); + map.set('protocol', this.getLocationProtocol()); result = this.formatString(result, map); } if (result === undefined) { @@ -74,6 +75,13 @@ export class AppConfigService { return result; } + /** + * Gets the location.protocol value. + */ + getLocationProtocol(): string { + return location.protocol; + } + /** * Gets the location.hostname property. * @returns Value of the property