Stuff for https
This commit is contained in:
parent
afbf7cb0d3
commit
e1bd05f7a5
3 changed files with 18 additions and 13 deletions
3
main.js
3
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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue