Stuff for https

This commit is contained in:
Daniel Lugo 2021-10-09 09:34:34 -04:00
parent afbf7cb0d3
commit e1bd05f7a5
3 changed files with 18 additions and 13 deletions

View file

@ -18,6 +18,9 @@ program
.option("-c, --mainnet", "run server on mainnet mode") .option("-c, --mainnet", "run server on mainnet mode")
.option("-t, --tunnel","create a localtunnel to listen behind a firewall") .option("-t, --tunnel","create a localtunnel to listen behind a firewall")
.option('-r, --lndaddress', 'Lnd address, defaults to 127.0.0.1:9735') .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); .parse(process.argv);
// load server // load server

View file

@ -47,7 +47,7 @@ module.exports = async (
app, app,
config, config,
mySocketsEvents, mySocketsEvents,
{ serverPort, CA, CA_KEY, usetls } { serverPort, CA, CA_KEY, useTLS }
) => { ) => {
try { try {
const Http = Axios.create({ const Http = Axios.create({
@ -85,7 +85,7 @@ module.exports = async (
try { try {
const APIHealth = await Http.get( const APIHealth = await Http.get(
`${usetls ? 'https' : 'http'}://localhost:${serverPort}/ping` `${useTLS ? 'https' : 'http'}://localhost:${serverPort}/ping`
) )
const APIStatus = { const APIStatus = {
message: APIHealth.data, message: APIHealth.data,

View file

@ -10,6 +10,8 @@ process.on('uncaughtException', e => {
*/ */
const server = program => { const server = program => {
const Http = require('http') const Http = require('http')
const Https = require('https')
const FS = require('fs')
const Express = require('express') const Express = require('express')
const Crypto = require('crypto') const Crypto = require('crypto')
const Dotenv = require('dotenv') const Dotenv = require('dotenv')
@ -294,20 +296,20 @@ const server = program => {
res.status(500).send({ status: 500, errorMessage: 'internal error' }) res.status(500).send({ status: 500, errorMessage: 'internal error' })
}) })
const CA = LightningServices.servicesConfig.lndCertPath const CA =
const CA_KEY = CA.replace('cert', 'key') program.httpsCert || LightningServices.servicesConfig.lndCertPath
const CA_KEY = program.httpsCertKey || CA.replace('cert', 'key')
const createServer = () => { const createServer = () => {
try { try {
// if (LightningServices.servicesConfig.lndCertPath && program.usetls) { if (LightningServices.servicesConfig.lndCertPath && program.useTLS) {
// const [key, cert] = await Promise.all([ const key = FS.readFileSync(CA_KEY, 'utf-8')
// FS.readFile(CA_KEY), const cert = FS.readFileSync(CA, 'utf-8')
// FS.readFile(CA)
// ])
// const httpsServer = Https.createServer({ key, cert }, app)
// return httpsServer const httpsServer = Https.createServer({ key, cert }, app)
// }
return httpsServer
}
const httpServer = Http.Server(app) const httpServer = Http.Server(app)
return httpServer return httpServer
@ -357,7 +359,7 @@ const server = program => {
{ {
serverHost, serverHost,
serverPort, serverPort,
usetls: program.usetls, useTLS: program.useTLS,
CA, CA,
CA_KEY CA_KEY
} }