Make servicecatalog/js able to do env overridable services

This commit is contained in:
Mustafa Gezen 2022-07-20 12:10:14 +02:00
parent 78cf89a3ae
commit 8e342ff2ba
Signed by untrusted user who does not match committer: mustafa
GPG Key ID: DCDF010D946438C1
2 changed files with 23 additions and 5 deletions

View File

@ -32,6 +32,15 @@
import os from 'os'; import os from 'os';
export function envOverridable(svcName, protocol, x) {
const envName = `${svcName}_${protocol}_ENDPOINT_OVERRIDE`.toUpperCase();
const envValue = process.env[envName];
if (envValue) {
return envValue;
}
return x();
}
export function svcName(svc, protocol) { export function svcName(svc, protocol) {
let env = process.env['BYC_ENV']; let env = process.env['BYC_ENV'];
if (!env) { if (!env) {

View File

@ -33,20 +33,29 @@
// noinspection JSUnresolvedFunction // noinspection JSUnresolvedFunction
// noinspection ES6PreferShortImport // noinspection ES6PreferShortImport
import { svcNameHttp, endpointHttp, NS } from '../../../common/frontend_server/upstream.mjs'; import {
svcNameHttp,
endpointHttp,
NS,
envOverridable
} from '../../../common/frontend_server/upstream.mjs';
import pkg from '@ory/hydra-client'; import pkg from '@ory/hydra-client';
import os from 'os'; import os from 'os';
const { Configuration, PublicApi, AdminApi } = pkg; const { Configuration, PublicApi, AdminApi } = pkg;
export function hydraPublicUrl() { export function hydraPublicUrl() {
const svc = svcNameHttp('hydra-public'); return envOverridable('hydra_public', 'http', () => {
return endpointHttp(svc, NS('hydra-public'), ':4444'); const svc = svcNameHttp('hydra-public');
return endpointHttp(svc, NS('hydra-public'), ':4444');
});
} }
function hydraAdminUrl() { function hydraAdminUrl() {
const svc = svcNameHttp('hydra-admin'); return envOverridable('hydra_admin', 'http', () => {
return endpointHttp(svc, NS('hydra-admin'), ':4445'); const svc = svcNameHttp('hydra-admin');
return endpointHttp(svc, NS('hydra-admin'), ':4445');
});
} }
const hydraAdmin = new AdminApi( const hydraAdmin = new AdminApi(