mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
optional port number (#2518)
This commit is contained in:
parent
c2cafaa648
commit
f9fc76a3ce
@ -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);
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user