Browse Source

Merge branch 'shesek-env-config'

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
03f0696750
  1. 21
      README.md
  2. 38
      app.js
  3. 14
      app/config.js
  4. 26
      app/defaultCredentials.js
  5. 1
      package.json

21
README.md

@ -38,10 +38,23 @@ The below instructions are geared toward BTC, but can be adapted easily to other
1. Clone this repo: `git clone https://github.com/janoside/btc-rpc-explorer` 1. Clone this repo: `git clone https://github.com/janoside/btc-rpc-explorer`
2. `npm install` 2. `npm install`
3. `npm run build` 3. `npm run build`
4. Optional: Create git-ignored file `app/credentials.js` with values to overwrite those in [app/defaultCredentials.js](app/defaultCredentials.js). 4. Set environment variables with your bitcoind rpc credentials and other settings. See [configuration](#configuration).
5. Optional: Change the "coin" value in [app/config.js](app/config.js). Currently supported values are "BTC" and "LTC". 5. `npm start`
6. `npm start` 6. Open [http://127.0.0.1:3002/](http://127.0.0.1:3002/)
7. Open [http://127.0.0.1:3002/](http://127.0.0.1:3002/)
### Configuration
Configuration options may be passed as environment variables.
You can also set them in a `.env` file in the root directory, in the following format:
```
BTCEXP_BITCOIND_HOST = localhost
BTCEXP_BITCOIND_PORT = 8332
BTCEXP_BITCOIND_USER = username
BTCEXP_BITCOIND_PASS = password
BTCEXP_IPSTACK_KEY = 0000aaaafffffgggggg
BTCEXP_COOKIEPASSWORD = 0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
```
## Run via Docker ## Run via Docker

38
app.js

@ -2,6 +2,8 @@
'use strict'; 'use strict';
require('dotenv').config();
var express = require('express'); var express = require('express');
var path = require('path'); var path = require('path');
var favicon = require('serve-favicon'); var favicon = require('serve-favicon');
@ -205,32 +207,19 @@ app.runOnStartup = function() {
console.log("Running RPC Explorer for " + global.coinConfig.name); console.log("Running RPC Explorer for " + global.coinConfig.name);
var rpcCredentials = null; var rpcCred = config.credentials.rpc;
if (config.credentials.rpc) { console.log("Connecting via RPC to node at " + rpcCred.host + ":" + rpcCred.port);
rpcCredentials = config.credentials.rpc;
} else if (process.env.RPC_HOST) {
rpcCredentials = {
host: process.env.RPC_HOST,
port: process.env.RPC_PORT,
username: process.env.RPC_USERNAME,
password: process.env.RPC_PASSWORD
};
}
if (rpcCredentials) {
console.log("Connecting via RPC to node at " + config.credentials.rpc.host + ":" + config.credentials.rpc.port);
global.client = new bitcoinCore({ global.client = new bitcoinCore({
host: rpcCredentials.host, host: rpcCred.host,
port: rpcCredentials.port, port: rpcCred.port,
username: rpcCredentials.username, username: rpcCred.username,
password: rpcCredentials.password, password: rpcCred.password,
timeout: 5000 timeout: 5000
}); });
coreApi.getNetworkInfo().then(function(getnetworkinfo) { coreApi.getNetworkInfo().then(function(getnetworkinfo) {
console.log("Connected via RPC to node. Basic info: version=" + getnetworkinfo.version + ", subversion=" + getnetworkinfo.subversion + ", protocolversion=" + getnetworkinfo.protocolversion + ", services=" + getnetworkinfo.localservices); console.log("Connected via RPC to node. Basic info: version=" + getnetworkinfo.version + ", subversion=" + getnetworkinfo.subversion + ", protocolversion=" + getnetworkinfo.protocolversion + ", services=" + getnetworkinfo.localservices);
if (config.credentials.influxdb.active) { if (config.credentials.influxdb.active) {
global.influxdb = new Influx.InfluxDB(config.credentials.influxdb); global.influxdb = new Influx.InfluxDB(config.credentials.influxdb);
@ -246,7 +235,6 @@ app.runOnStartup = function() {
}).catch(function(err) { }).catch(function(err) {
console.log("Error 923grf20fge: " + err + ", error json: " + JSON.stringify(err)); console.log("Error 923grf20fge: " + err + ", error json: " + JSON.stringify(err));
}); });
}
if (config.donationAddresses) { if (config.donationAddresses) {
var getDonationAddressQrCode = function(coinId) { var getDonationAddressQrCode = function(coinId) {

14
app/config.js

@ -1,17 +1,15 @@
var coins = require("./coins.js"); var coins = require("./coins.js");
var currentCoin = "BTC"; var currentCoin = process.env.BTCEXP_COIN || "BTC";
var credentials = require("./defaultCredentials.js"); var credentials = require("./defaultCredentials.js");
var overwriteCredentials = require("./credentials.js"); try {
Object.assign(credentials, require("./credentials.js"))
for (var key in overwriteCredentials) { } catch (err) {}
credentials[key] = overwriteCredentials[key];
}
module.exports = { module.exports = {
cookiePassword: "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", cookiePassword: process.env.BTCEXP_COOKIE_PASSWORD || "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
demoSite: true, demoSite: !!process.env.BTCEXP_DEMO,
coin: currentCoin, coin: currentCoin,
rpcBlacklist:[ rpcBlacklist:[

26
app/defaultCredentials.js

@ -1,31 +1,31 @@
module.exports = { module.exports = {
rpc: { rpc: {
host:"127.0.0.1", host: process.env.BTCEXP_BITCOIND_HOST || "127.0.0.1",
port:8332, port: process.env.BTCEXP_BITCOIND_PORT || 8332,
username:"rpc_username", username: process.env.BTCEXP_BITCOIND_USER,
password:"rpc_password" password: process.env.BTCEXP_BITCOIND_PASS,
}, },
influxdb:{ influxdb:{
active:false, active: !!process.env.BTCEXP_INFLUXDB_ENABLED,
host:"127.0.0.1", host: process.env.BTCEXP_INFLUXDB_HOST || "127.0.0.1",
port:8086, port: process.env.BTCEXP_INFLUXDB_PORT || 8086,
database:"influxdb", database: process.env.BTCEXP_INFLUXDB_DB || "influxdb",
username:"admin", username: process.env.BTCEXP_INFLUXDB_USER || "admin",
password:"admin" password: process.env.BTCEXP_INFLUXDB_PASS || "admin"
}, },
// optional: enter your api access key from ipstack.com below // optional: enter your api access key from ipstack.com below
// to include a map of the estimated locations of your node's // to include a map of the estimated locations of your node's
// peers // peers
// format: "ID_FROM_IPSTACK" // format: "ID_FROM_IPSTACK"
ipStackComApiAccessKey:null, ipStackComApiAccessKey: process.env.BTCEXP_IPSTACK_KEY,
// optional: GA tracking code // optional: GA tracking code
// format: "UA-..." // format: "UA-..."
googleAnalyticsTrackingId:null, googleAnalyticsTrackingId: process.env.BTCEXP_GANALYTICS_TRACKING,
// optional: sentry.io error-tracking url // optional: sentry.io error-tracking url
// format: "SENTRY_IO_URL" // format: "SENTRY_IO_URL"
sentryUrl:null, sentryUrl: process.env.BTCEXP_SENTRY_URL,
}; };

1
package.json

@ -27,6 +27,7 @@
"crypto-js": "3.1.9-1", "crypto-js": "3.1.9-1",
"debug": "~2.6.0", "debug": "~2.6.0",
"decimal.js": "7.2.3", "decimal.js": "7.2.3",
"dotenv": "^6.2.0",
"electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5", "electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5",
"express": "^4.16.4", "express": "^4.16.4",
"express-session": "1.15.6", "express-session": "1.15.6",

Loading…
Cancel
Save