Skip to content

Commit

Permalink
[AAE-18459] Replace all placeholders if the configuration key is an o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
alep85 committed Dec 11, 2023
1 parent cd33bb6 commit 5a16692
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/core/src/lib/app-config/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,20 @@ describe('AppConfigService', () => {
expect(fakeCallBack).toHaveBeenCalled();
});

it('should replace all the configuration placeholders if the provided key is an object', () => {
appConfigService.config.objectKey = {
firstUrl: '{protocol}//{hostname}{:port}',
secondUrl: '{protocol}//{hostname}{:port}',
thirdUrl: '{protocol}//{hostname}{:port}'
};
spyOn(appConfigService, 'getLocationHostname').and.returnValue('localhost');
spyOn(appConfigService, 'getLocationPort').and.returnValue(':8080');
spyOn(appConfigService, 'getLocationProtocol').and.returnValue('http:');

expect(appConfigService.get<any>('objectKey').firstUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').secondUrl).toEqual('http://localhost:8080');
expect(appConfigService.get<any>('objectKey').thirdUrl).toEqual('http://localhost:8080');
});


});
7 changes: 4 additions & 3 deletions lib/core/src/lib/app-config/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ export class AppConfigService {
}

if (typeof result === 'object') {
result = JSON.parse(JSON.stringify(result).replace('{hostname}', this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace('{:port}', this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace('{protocol}', this.getLocationProtocol()));
result = JSON.parse(JSON.stringify(result).replace(/{hostname}/g, this.getLocationHostname()));
result = JSON.parse(JSON.stringify(result).replace(/{:port}/g, this.getLocationPort(':')));
result = JSON.parse(JSON.stringify(result).replace(/{protocol}/g, this.getLocationProtocol()));
}

if (result === undefined) {
Expand Down Expand Up @@ -255,6 +255,7 @@ export class AppConfigService {
const silentLogin = config['silentLogin'] === true || config['silentLogin'] === 'true';
const codeFlow = config['codeFlow'] === true || config['codeFlow'] === 'true';

console.log('config: ', config);
return {
...(config as OauthConfigModel),
implicitFlow,
Expand Down

0 comments on commit 5a16692

Please sign in to comment.