Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions packages/bitcore-wallet-service/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import { logger } from './lib/logger';

const Config = (): any => {
let defaultConfig = {
const defaultConfig = {
basePath: '/bws/api',
disableLogs: false,
port: 3232,
Expand Down Expand Up @@ -476,12 +478,36 @@ const Config = (): any => {
};

// Override default values with bws.config.js' values, if present
const { BITCORE_CONFIG_PATH = '../../', BWS_CONFIG_PATH = '../../' } = process.env;
let bwsConfig;

try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const bwsConfig = require('../../bws.config');
defaultConfig = _.merge(defaultConfig, bwsConfig);
} catch {
logger.info('bws.config.js not found, using default configuration values');
if (BITCORE_CONFIG_PATH) {
if (fs.existsSync(path.join(BITCORE_CONFIG_PATH, 'bitcore.config.json'))) {
bwsConfig = JSON.parse(fs.readFileSync(path.join(BITCORE_CONFIG_PATH, 'bitcore.config.json'), 'utf8'));
} else if (fs.existsSync(BITCORE_CONFIG_PATH) && BITCORE_CONFIG_PATH.endsWith('.json')) {
bwsConfig = JSON.parse(fs.readFileSync(BITCORE_CONFIG_PATH, 'utf8'));
}
bwsConfig = bwsConfig?.bitcoreWalletService;
}

if (!bwsConfig && BWS_CONFIG_PATH) {
if (fs.existsSync(path.join(BWS_CONFIG_PATH, 'bws.config.js'))) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
bwsConfig = require(path.join(BWS_CONFIG_PATH, 'bws.config.js'));
} else if (fs.existsSync(BWS_CONFIG_PATH) && BWS_CONFIG_PATH.endsWith('.js')) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
bwsConfig = require(BWS_CONFIG_PATH);
}
}

if (!bwsConfig) {
logger.info('No config file found. Using default configuration values');
}

bwsConfig = _.merge(defaultConfig, bwsConfig);
} catch (err) {
throw new Error('Error loading config file:\n' + err.stack);
}

if (process.env.SENDGRID_API_KEY) {
Expand Down