diff --git a/common.js b/common.js index 62d6bfdd..e01f31de 100644 --- a/common.js +++ b/common.js @@ -1,5 +1,6 @@ var fs = require('fs'); var crypto = require('crypto'); +var path = require('path'); var common = {}; common.multi_node_setup = false; @@ -33,10 +34,10 @@ common.setOptions = () => { json: true, form: '' }; - if (node.ln_implementation.toUpperCase() !== 'CLT') { - node.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(node.macaroon_path + '/admin.macaroon').toString('hex') }; + if (node.ln_implementation && node.ln_implementation.toUpperCase() === 'CLT') { + node.options.headers = { 'macaroon': Buffer.from(fs.readFileSync(path.join(node.macaroon_path, 'access.macaroon'))).toString("base64") }; } else { - node.options.headers = { 'macaroon': Buffer.from(fs.readFileSync(node.macaroon_path + '/access.macaroon')).toString("base64") }; + node.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(path.join(node.macaroon_path, 'admin.macaroon')).toString('hex') }; } }); // Options cannot be set before selected node initializes. Updating selected node's options separatly @@ -46,10 +47,10 @@ common.setOptions = () => { json: true, form: '' }; - if (common.selectedNode.ln_implementation.toUpperCase() !== 'CLT') { - common.selectedNode.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(common.selectedNode.macaroon_path + '/admin.macaroon').toString('hex') }; + if (common.selectedNode && common.selectedNode.ln_implementation && common.selectedNode.ln_implementation.toUpperCase() === 'CLT') { + common.selectedNode.options.headers = { 'macaroon': Buffer.from(fs.readFileSync(path.join(common.selectedNode.macaroon_path, 'access.macaroon'))).toString("base64") }; } else { - common.selectedNode.options.headers = { 'macaroon': Buffer.from(fs.readFileSync(common.selectedNode.macaroon_path + '/access.macaroon')).toString("base64") }; + common.selectedNode.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(path.join(common.selectedNode.macaroon_path, 'admin.macaroon')).toString('hex') }; } } catch (err) { console.error('Common Set Options Error:' + JSON.stringify(err)); diff --git a/controllers/RTLConf.js b/controllers/RTLConf.js index dc32ad58..38b6495f 100644 --- a/controllers/RTLConf.js +++ b/controllers/RTLConf.js @@ -6,8 +6,9 @@ var common = require('../common'); exports.updateSelectedNode = (req, res, next) => { const selNodeIndex = req.body.selNodeIndex; common.selectedNode = common.findNode(selNodeIndex); - logger.info({fileName: 'RTLConf', msg: 'Selected Node Updated To: ' + JSON.stringify(common.selectedNode.ln_node)}); - res.status(200).json({status: 'Selected Node Updated To: ' + JSON.stringify(common.selectedNode.ln_node) + '!'}); + const responseVal = common.selectedNode.ln_node ? common.selectedNode.ln_node : common.selectedNode.ln_server_url; + logger.info({fileName: 'RTLConf', msg: 'Selected Node Updated To: ' + JSON.stringify(responseVal)}); + res.status(200).json({status: 'Selected Node Updated To: ' + JSON.stringify(responseVal) + '!'}); }; exports.getRTLConfig = (req, res, next) => {