From 8ab1ddc9151a979af5d53371afb60818a9390107 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Mon, 22 Jun 2020 14:28:55 -0400 Subject: [PATCH] More work related to #219 Stop using type=boolean for args via cli since they force the default value false. Rather, use the default-setting code in config.js for both cli args and env vars. Also add some additional logging to help debugging issues like this in the future --- app/config.js | 32 +++++++++++++++++++++++++++++--- bin/cli.js | 26 +++++++++++++++----------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/app/config.js b/app/config.js index fb436fa..d1b2e59 100644 --- a/app/config.js +++ b/app/config.js @@ -1,3 +1,6 @@ +var debug = require("debug"); +var debugLog = debug("btcexp:config"); + var fs = require('fs'); var crypto = require('crypto'); var url = require('url'); @@ -33,15 +36,33 @@ for (var i = 0; i < electrumXServerUriStrings.length; i++) { electrumXServers.push({protocol:uri.protocol.substring(0, uri.protocol.length - 1), host:uri.hostname, port:parseInt(uri.port)}); } -["BTCEXP_DEMO", "BTCEXP_PRIVACY_MODE", "BTCEXP_NO_INMEMORY_RPC_CACHE"].forEach(function(item) { +// default=false env vars +[ + "BTCEXP_DEMO", + "BTCEXP_PRIVACY_MODE", + "BTCEXP_NO_INMEMORY_RPC_CACHE", + "BTCEXP_RPC_ALLOWALL" + +].forEach(function(item) { if (process.env[item] === undefined) { process.env[item] = "false"; + + debugLog(`Config(default): ${item}=false`) } }); -["BTCEXP_NO_RATES", "BTCEXP_UI_SHOW_TOOLS_SUBHEADER", "BTCEXP_SLOW_DEVICE_MODE"].forEach(function(item) { + +// default=true env vars +[ + "BTCEXP_NO_RATES", + "BTCEXP_UI_SHOW_TOOLS_SUBHEADER", + "BTCEXP_SLOW_DEVICE_MODE" + +].forEach(function(item) { if (process.env[item] === undefined) { process.env[item] = "true"; + + debugLog(`Config(default): ${item}=true`) } }); @@ -59,7 +80,7 @@ module.exports = { rpcConcurrency: (process.env.BTCEXP_RPC_CONCURRENCY || 10), rpcBlacklist: - process.env.BTCEXP_RPC_ALLOWALL ? [] + process.env.BTCEXP_RPC_ALLOWALL.toLowerCase() == "true" ? [] : process.env.BTCEXP_RPC_BLACKLIST ? process.env.BTCEXP_RPC_BLACKLIST.split(',').filter(Boolean) : [ "addnode", @@ -206,3 +227,8 @@ module.exports = { } } }; + +debugLog(`Config(final): privacyMode=${module.exports.privacyMode}`); +debugLog(`Config(final): slowDeviceMode=${module.exports.slowDeviceMode}`); +debugLog(`Config(final): demo=${module.exports.demoSite}`); +debugLog(`Config(final): rpcAllowAll=${module.exports.rpcBlacklist.length == 0}`); diff --git a/bin/cli.js b/bin/cli.js index d671c5b..84eb094 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,5 +1,11 @@ #!/usr/bin/env node +var debug = require("debug"); +var debugLog = debug("btcexp:config"); + +// to debug arg settings, enable the below line: +//debug.enable("btcexp:*"); + const args = require('meow')(` Usage $ btc-rpc-explorer [options] @@ -60,29 +66,27 @@ const args = require('meow')(` bitcoindCookie: {alias:'c'}, bitcoindUser: {alias:'u'}, bitcoindPass: {alias:'w'}, - demo: {type:'boolean'}, - rpcAllowall: {type:'boolean'}, + demo: {}, + rpcAllowall: {}, electrumxServers: {alias:'E'}, nodeEnv: {alias:'e', default:'production'}, - privacyMode: {type:'boolean'}, - slowDeviceMode: {type:'boolean'} + privacyMode: {}, + slowDeviceMode: {} } } ).flags; const envify = k => k.replace(/([A-Z])/g, '_$1').toUpperCase(); -var defaultTrueWithoutNoPrefixVars = [ "SLOW_DEVICE_MODE" ]; - Object.keys(args).filter(k => k.length > 1).forEach(k => { if (args[k] === false) { - if (defaultTrueWithoutNoPrefixVars.includes(envify(k))) { - process.env[`BTCEXP_${envify(k)}`] = false; + debugLog(`Config(arg): BTCEXP_NO_${envify(k)}=true`); + + process.env[`BTCEXP_NO_${envify(k)}`] = true; - } else { - process.env[`BTCEXP_NO_${envify(k)}`] = true; - } } else { + debugLog(`Config(arg): BTCEXP_${envify(k)}=${args[k]}`); + process.env[`BTCEXP_${envify(k)}`] = args[k]; } });