Skip to content

Commit

Permalink
Moved configuration to .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Nov 5, 2022
1 parent 8e2fdfc commit 69d09ad
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC_CREDENTIALS=username:password
ALLOWED_RPCS=help,listmasternodes
PORT = 3000
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
.env
38 changes: 12 additions & 26 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
import * as dotenv from "dotenv";
dotenv.config();
checkEnv();
import express from "express";
import fetch from "node-fetch";

const app = express()
const port = 3000
const allowedRpcs = ["getbalance", "help"];
const port = process.env["PORT"] || 3000;
const allowedRpcs = process.env["ALLOWED_RPCS"].split(",");

export const encodeBase64 = (data) => {
return Buffer.from(data).toString('base64');
function checkEnv() {
if(!process.env["ALLOWED_RPCS"]) throw new Error("Environment variable ALLOWED_RPCS was not set");
if(!process.env["RPC_CREDENTIALS"]) throw new Error("Environment variable RPC_CREDENTIALS was not set");
}

/*
fetch('http://127.0.0.1:51473/', {
method: 'POST',
headers: {
'content-type': 'text/plain;',
'Authorization': 'Basic ' + encodeBase64btoa('masternode_test:p')
},
body: '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": [] }'
}).then(res => res.text())
.then(text => console.log(text));
*/

(async () => {
try {
await fetch(url, {signal});
} catch (error) {
if (error.name === 'AbortError') {
console.log('request was aborted');
}
}
})();
const encodeBase64 = (data) => {
return Buffer.from(data).toString('base64');
}

async function makeRpc(name, ...params){
try{
const output = await fetch('http://127.0.0.1:51473/', {
method: 'POST',
headers: {
'content-type': 'text/plain;',
'Authorization': 'Basic ' + encodeBase64('masternode_test:p')
'Authorization': 'Basic ' + encodeBase64(process.env["RPC_CREDENTIALS"])
},
body: JSON.stringify({
jsonrpc: "1.0",
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"homepage": "https://github.com/Shangaman/PivxNodeController#readme",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"node-fetch": "^3.2.10"
}
Expand Down

0 comments on commit 69d09ad

Please sign in to comment.