Skip to content

Commit

Permalink
added hosts and server components
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pyrathon authored and mably committed Sep 28, 2018
1 parent cc62244 commit acfa1f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
6 changes: 1 addition & 5 deletions app/server-le.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ module.exports = function (program) {
// db init =================
const db = require("./database")(defaults.dataPath);

// setup lightning client =================
const lndHost = program.lndhost || defaults.lndHost;
const lndCertPath = program.lndCertPath || defaults.lndCertPath;
const macaroonPath = program.macaroonPath || defaults.macaroonPath;
const lightning = require("./lightning")(defaults.lndProto, lndHost, lndCertPath, macaroonPath);
var lightning = module.makeLightningManager(program);

// init lnd module =================
const lnd = require("./lnd")(lightning);
Expand Down
19 changes: 19 additions & 0 deletions app/server-utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
// app/utils.js

const debug = require("debug")("lncliweb:utils");
const defaults = require("../config/defaults");
const logger = require("winston");
const LightningManager = require('./lightning')

// TODO
module.exports = function (server) {

var module = {};

server.makeLightningManager = function(program) {
var lndHost = program.lndhost || defaults.lndHost;
var lndCertPath = program.lndCertPath || defaults.lndCertPath;

// If `disableMacaroon` is set, ignore macaroon support for the session. Otherwise
// we read from `macarooonPath` variable and alternatively fallback to default `macaroonPath`.
var macaroonPath = null;
if (program.disableMacaroon) {
console.log("Macaroon support is disabled")
} else {
macaroonPath = program.macaroonPath || defaults.macaroonPath;
console.log("Macaroon support is enabled. Macaroon path is " + macaroonPath);
}

return new LightningManager(defaults.lndProto, lndHost, lndCertPath, macaroonPath);
}

server.getURL = function () {
return "http" + (this.useTLS ? "s" : "") + "://" + this.serverHost
+ (this.useTLS
Expand Down
20 changes: 1 addition & 19 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require("express");
const session = require("express-session");
const bodyParser = require("body-parser"); // pull information from HTML POST (express4)
const methodOverride = require("method-override"); // simulate DELETE and PUT (express4)
const LightningManager = require("./lightning");

// expose the server to our app with module.exports
module.exports = function (program) {
Expand Down Expand Up @@ -35,24 +34,7 @@ module.exports = function (program) {
// db init =================
const db = require("./database")(defaults.dataPath);

// setup lightning client =================
const lndHost = program.lndhost || defaults.lndHost;


// define macaroon configuration here.
const lndCertPath = program.lndCertPath || defaults.lndCertPath;

// If `disableMacaroon` is set, ignore macaroon support for the session. Otherwise
// we read from `macarooonPath` variable and alternatively fallback to default `macaroonPath`.
var macaroonPath = null;
if (program.disableMacaroon) {
console.log("Macaroon support is disabled")
} else {
macaroonPath = program.macaroonPath || defaults.macaroonPath;
console.log("Macaroon support is enabled. Macaroon path is " + macaroonPath);
}

var lightning = new LightningManager(defaults.lndProto, lndHost, lndCertPath, macaroonPath);
var lightning = module.makeLightningManager(program);

// init lnd module =================
const lnd = require("./lnd")(lightning);
Expand Down

0 comments on commit acfa1f3

Please sign in to comment.