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();
|
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', () => {
|
it('should load external settings', () => {
|
||||||
appConfigService.load().then(config => {
|
appConfigService.load().then(config => {
|
||||||
expect(config).toEqual(mockResponse);
|
expect(config).toEqual(mockResponse);
|
||||||
|
@ -28,8 +28,8 @@ export class AppConfigService {
|
|||||||
application: {
|
application: {
|
||||||
name: 'Alfresco ADF Application'
|
name: 'Alfresco ADF Application'
|
||||||
},
|
},
|
||||||
ecmHost: 'http://{hostname}:{port}/ecm',
|
ecmHost: 'http://{hostname}{:port}/ecm',
|
||||||
bpmHost: 'http://{hostname}:{port}/bpm'
|
bpmHost: 'http://{hostname}{:port}/bpm'
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(private http: Http) {}
|
constructor(private http: Http) {}
|
||||||
@ -38,8 +38,9 @@ export class AppConfigService {
|
|||||||
let result: any = ObjectUtils.getValue(this.config, key);
|
let result: any = ObjectUtils.getValue(this.config, key);
|
||||||
if (typeof result === 'string') {
|
if (typeof result === 'string') {
|
||||||
const map = new Map<string, string>();
|
const map = new Map<string, string>();
|
||||||
map.set('hostname', location.hostname);
|
map.set('hostname', this.getLocationHostname());
|
||||||
map.set('port', location.port);
|
map.set(':port', this.getLocationPort(':'));
|
||||||
|
map.set('port', this.getLocationPort());
|
||||||
result = this.formatString(result, map);
|
result = this.formatString(result, map);
|
||||||
}
|
}
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
@ -48,6 +49,14 @@ export class AppConfigService {
|
|||||||
return <T> result;
|
return <T> result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLocationHostname(): string {
|
||||||
|
return location.hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLocationPort(prefix: string = ''): string {
|
||||||
|
return location.port ? prefix + location.port : '';
|
||||||
|
}
|
||||||
|
|
||||||
load(): Promise<any> {
|
load(): Promise<any> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this.http.get('app.config.json').subscribe(
|
this.http.get('app.config.json').subscribe(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user