[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
This commit is contained in:
Denys Vuika 2018-05-15 13:10:27 +01:00 committed by GitHub
parent f159fbaa2c
commit db7d0b7c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -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` |

View File

@ -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);

View File

@ -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 <T> result;
}
/**
* Gets the location.protocol value.
*/
getLocationProtocol(): string {
return location.protocol;
}
/**
* Gets the location.hostname property.
* @returns Value of the property