diff --git a/main.js b/main.js index bab89bcb..05685d0d 100644 --- a/main.js +++ b/main.js @@ -18,6 +18,9 @@ program .option("-c, --mainnet", "run server on mainnet mode") .option("-t, --tunnel","create a localtunnel to listen behind a firewall") .option('-r, --lndaddress', 'Lnd address, defaults to 127.0.0.1:9735') + .option('-a, --use-TLS', 'use TLS') + .option('-i, --https-cert [path]', 'HTTPS certificate path') + .option('-y, --https-cert-key [path]', 'HTTPS certificate key path') .parse(process.argv); // load server diff --git a/src/routes.js b/src/routes.js index d340921d..23ca42be 100644 --- a/src/routes.js +++ b/src/routes.js @@ -47,7 +47,7 @@ module.exports = async ( app, config, mySocketsEvents, - { serverPort, CA, CA_KEY, usetls } + { serverPort, CA, CA_KEY, useTLS } ) => { try { const Http = Axios.create({ @@ -85,7 +85,7 @@ module.exports = async ( try { const APIHealth = await Http.get( - `${usetls ? 'https' : 'http'}://localhost:${serverPort}/ping` + `${useTLS ? 'https' : 'http'}://localhost:${serverPort}/ping` ) const APIStatus = { message: APIHealth.data, diff --git a/src/server.js b/src/server.js index 1b14e226..8af455e4 100644 --- a/src/server.js +++ b/src/server.js @@ -10,6 +10,8 @@ process.on('uncaughtException', e => { */ const server = program => { const Http = require('http') + const Https = require('https') + const FS = require('fs') const Express = require('express') const Crypto = require('crypto') const Dotenv = require('dotenv') @@ -294,20 +296,20 @@ const server = program => { res.status(500).send({ status: 500, errorMessage: 'internal error' }) }) - const CA = LightningServices.servicesConfig.lndCertPath - const CA_KEY = CA.replace('cert', 'key') + const CA = + program.httpsCert || LightningServices.servicesConfig.lndCertPath + const CA_KEY = program.httpsCertKey || CA.replace('cert', 'key') const createServer = () => { try { - // if (LightningServices.servicesConfig.lndCertPath && program.usetls) { - // const [key, cert] = await Promise.all([ - // FS.readFile(CA_KEY), - // FS.readFile(CA) - // ]) - // const httpsServer = Https.createServer({ key, cert }, app) + if (LightningServices.servicesConfig.lndCertPath && program.useTLS) { + const key = FS.readFileSync(CA_KEY, 'utf-8') + const cert = FS.readFileSync(CA, 'utf-8') - // return httpsServer - // } + const httpsServer = Https.createServer({ key, cert }, app) + + return httpsServer + } const httpServer = Http.Server(app) return httpServer @@ -357,7 +359,7 @@ const server = program => { { serverHost, serverPort, - usetls: program.usetls, + useTLS: program.useTLS, CA, CA_KEY }