From 1633c94232df84cfe5bac29ed5868bcdec90ee24 Mon Sep 17 00:00:00 2001 From: pketki Date: Thu, 30 Oct 2025 14:49:22 -0400 Subject: [PATCH] Initialize client only if config files exist Signed-off-by: pketki --- onboarding-enabler-nodejs/src/EurekaClient.js | 19 +++------- onboarding-enabler-nodejs/src/index.js | 38 ++++++++++++------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/onboarding-enabler-nodejs/src/EurekaClient.js b/onboarding-enabler-nodejs/src/EurekaClient.js index 53079f2f95..d12068290e 100644 --- a/onboarding-enabler-nodejs/src/EurekaClient.js +++ b/onboarding-enabler-nodejs/src/EurekaClient.js @@ -90,21 +90,14 @@ export default class Eureka extends EventEmitter { const cwd = config.cwd || process.cwd(); const env = process.env.EUREKA_ENV || process.env.NODE_ENV || 'development'; - // Config can either be passed via config file or as json - // Check if config file and cwd was provided - if (cwd) { - const filename = config.filename || 'eureka-client'; + const filename = config.filename || 'eureka-client'; - // Load in the configuration files: - const defaultYml = getYaml(path.join(cwd, `${filename}.yml`)); - const envYml = getYaml(path.join(cwd, `${filename}-${env}.yml`)); + // Load in the configuration files: + const defaultYml = getYaml(path.join(cwd, `${filename}.yml`)); + const envYml = getYaml(path.join(cwd, `${filename}-${env}.yml`)); - // apply config overrides in appropriate order - this.config = merge({}, defaultConfig, defaultYml, envYml, config); - } else { - // config was provided as JSON - this.config = config; - } + // apply config overrides in appropriate order + this.config = merge({}, defaultConfig, defaultYml, envYml, config); // Validate the provided the values we need: this.validateConfig(this.config); diff --git a/onboarding-enabler-nodejs/src/index.js b/onboarding-enabler-nodejs/src/index.js index 1c56cca8f1..a6704cff2f 100644 --- a/onboarding-enabler-nodejs/src/index.js +++ b/onboarding-enabler-nodejs/src/index.js @@ -16,6 +16,8 @@ let certFile = null; let keyFile = null; let caFile = null; let passPhrase = null; +let client = null; +let tlsOpts = null; /** * Read ssl service configuration @@ -31,22 +33,30 @@ function readTlsProps() { console.log(e); } } -readTlsProps(); -export const tlsOptions = { - cert: fs.readFileSync(certFile), - key: fs.readFileSync(keyFile), - passphrase: passPhrase, - ca: fs.readFileSync(caFile), -}; +export const tlsOptions = tlsOpts; -const client = new Eureka({ - filename: 'service-configuration', - cwd: 'config/', - requestMiddleware: (requestOpts, done) => { - done(Object.assign(requestOpts, tlsOptions)); - }, -}); +function init () { + const defaultFile = fs.existsSync('config/service-configuration.yml', 'utf8'); + if (defaultFile) { + readTlsProps(); + tlsOpts = { + cert: fs.readFileSync(certFile), + key: fs.readFileSync(keyFile), + passphrase: passPhrase, + ca: fs.readFileSync(caFile), + }; + client = new Eureka({ + filename: 'service-configuration', + cwd: 'config/', + requestMiddleware: (requestOpts, done) => { + done(Object.assign(requestOpts, tlsOpts)); + }, + }); + } +} + +init(); /** * Function that uses the eureka-js-client library to register the application to Eureka