Skip to content

Commit

Permalink
compact the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiKamilla committed Oct 6, 2023
1 parent 3c3e00c commit 52ae447
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/routes/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,34 +151,19 @@ router.all('/common-services/**', async (req, res) => {
status: 'active',
authType: 'service-to-service',
endpoint: config.get<string>('commonServices.url'),
settings: {
authTargetUrl: config.get<string>('commonServices.authUrl'),
apiClientId: config.get<string>('commonServices.clientId'),
scope: config.get<string>('commonServices.scope'),
secret: config.get<string>('commonServices.clientSecret'),
},
};

//encrypt settings
const settings = {
authTargetUrl: commonServiceConfig.settings.authTargetUrl,
apiClientID: commonServiceConfig.settings.apiClientId,
scope: commonServiceConfig.settings.scope,
safeSecret: commonServiceConfig.settings.secret,
};
const encryptedSettings = CryptoJS.AES.encrypt(
JSON.stringify(settings),
config.get('encryption.key')
).toString();

//save common service config
const commonServiceConfigToSave = {
...commonServiceConfig,
settings: encryptedSettings,
settings: CryptoJS.AES.encrypt(
JSON.stringify({
authTargetUrl: config.get<string>('commonServices.authUrl'),
apiClientID: config.get<string>('commonServices.clientId'),
scope: config.get<string>('commonServices.scope'),
safeSecret: config.get<string>('commonServices.clientSecret'),
}),
config.get('encryption.key')
).toString(),
};

try {
const api = new ApiConfiguration(commonServiceConfigToSave);
const api = new ApiConfiguration(commonServiceConfig);
const path = req.originalUrl.split('common-services').pop().substring(1);
await proxyAPIRequest(req, res, api, path);
} catch (err) {
Expand Down

0 comments on commit 52ae447

Please sign in to comment.