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`
2. `npm install`
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).
5. Optional: Change the "coin" value in [app/config.js](app/config.js). Currently supported values are "BTC" and "LTC".
6. `npm start`
7. Open [http://127.0.0.1:3002/](http://127.0.0.1:3002/)
4. Set environment variables with your bitcoind rpc credentials and other settings. See [configuration](#configuration).
5. `npm start`
6. 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

38
app.js

@ -2,6 +2,8 @@
'use strict';
require('dotenv').config();
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
@ -205,32 +207,19 @@ app.runOnStartup = function() {
console.log("Running RPC Explorer for " + global.coinConfig.name);
var rpcCredentials = null;
if (config.credentials.rpc) {
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);
var rpcCred = config.credentials.rpc;
console.log("Connecting via RPC to node at " + rpcCred.host + ":" + rpcCred.port);
global.client = new bitcoinCore({
host: rpcCredentials.host,
port: rpcCredentials.port,
username: rpcCredentials.username,
password: rpcCredentials.password,
timeout: 5000
});
global.client = new bitcoinCore({
host: rpcCred.host,
port: rpcCred.port,
username: rpcCred.username,
password: rpcCred.password,
timeout: 5000
});
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);
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);
if (config.credentials.influxdb.active) {
global.influxdb = new Influx.InfluxDB(config.credentials.influxdb);
@ -246,7 +235,6 @@ app.runOnStartup = function() {
}).catch(function(err) {
console.log("Error 923grf20fge: " + err + ", error json: " + JSON.stringify(err));
});
}
if (config.donationAddresses) {
var getDonationAddressQrCode = function(coinId) {

14
app/config.js

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

26
app/defaultCredentials.js

@ -1,31 +1,31 @@
module.exports = {
rpc: {
host:"127.0.0.1",
port:8332,
username:"rpc_username",
password:"rpc_password"
host: process.env.BTCEXP_BITCOIND_HOST || "127.0.0.1",
port: process.env.BTCEXP_BITCOIND_PORT || 8332,
username: process.env.BTCEXP_BITCOIND_USER,
password: process.env.BTCEXP_BITCOIND_PASS,
},
influxdb:{
active:false,
host:"127.0.0.1",
port:8086,
database:"influxdb",
username:"admin",
password:"admin"
active: !!process.env.BTCEXP_INFLUXDB_ENABLED,
host: process.env.BTCEXP_INFLUXDB_HOST || "127.0.0.1",
port: process.env.BTCEXP_INFLUXDB_PORT || 8086,
database: process.env.BTCEXP_INFLUXDB_DB || "influxdb",
username: process.env.BTCEXP_INFLUXDB_USER || "admin",
password: process.env.BTCEXP_INFLUXDB_PASS || "admin"
},
// optional: enter your api access key from ipstack.com below
// to include a map of the estimated locations of your node's
// peers
// format: "ID_FROM_IPSTACK"
ipStackComApiAccessKey:null,
ipStackComApiAccessKey: process.env.BTCEXP_IPSTACK_KEY,
// optional: GA tracking code
// format: "UA-..."
googleAnalyticsTrackingId:null,
googleAnalyticsTrackingId: process.env.BTCEXP_GANALYTICS_TRACKING,
// optional: sentry.io error-tracking 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",
"debug": "~2.6.0",
"decimal.js": "7.2.3",
"dotenv": "^6.2.0",
"electrum-client": "github:chaintools/node-electrum-client#43a999036f9c5",
"express": "^4.16.4",
"express-session": "1.15.6",

Loading…
Cancel
Save