Browse Source

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
master
Dan Janosik 4 years ago
parent
commit
8ab1ddc915
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 32
      app/config.js
  2. 26
      bin/cli.js

32
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}`);

26
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];
}
});

Loading…
Cancel
Save