From 8e342ff2ba519f15b2ed9c8fcf805b60d3d00197 Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Wed, 20 Jul 2022 12:10:14 +0200 Subject: [PATCH] Make servicecatalog/js able to do env overridable services --- common/frontend_server/upstream.mjs | 9 +++++++++ hydra/pkg/hydra/autosignup.mjs | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common/frontend_server/upstream.mjs b/common/frontend_server/upstream.mjs index 3f7bf3ea..7d4a6443 100644 --- a/common/frontend_server/upstream.mjs +++ b/common/frontend_server/upstream.mjs @@ -32,6 +32,15 @@ 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) { let env = process.env['BYC_ENV']; if (!env) { diff --git a/hydra/pkg/hydra/autosignup.mjs b/hydra/pkg/hydra/autosignup.mjs index 4247973a..dccc9a9c 100644 --- a/hydra/pkg/hydra/autosignup.mjs +++ b/hydra/pkg/hydra/autosignup.mjs @@ -33,20 +33,29 @@ // noinspection JSUnresolvedFunction // 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 os from 'os'; const { Configuration, PublicApi, AdminApi } = pkg; export function hydraPublicUrl() { - const svc = svcNameHttp('hydra-public'); - return endpointHttp(svc, NS('hydra-public'), ':4444'); + return envOverridable('hydra_public', 'http', () => { + const svc = svcNameHttp('hydra-public'); + return endpointHttp(svc, NS('hydra-public'), ':4444'); + }); } function hydraAdminUrl() { - const svc = svcNameHttp('hydra-admin'); - return endpointHttp(svc, NS('hydra-admin'), ':4445'); + return envOverridable('hydra_admin', 'http', () => { + const svc = svcNameHttp('hydra-admin'); + return endpointHttp(svc, NS('hydra-admin'), ':4445'); + }); } const hydraAdmin = new AdminApi(