From 4501f71dd8f405e9eca433c87e093f31db3b1a68 Mon Sep 17 00:00:00 2001 From: Adrian Woeltche Date: Thu, 21 Jun 2018 16:41:45 +0200 Subject: [PATCH 1/2] permit https --- config/default.toml | 10 ++++++++++ index.js | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/default.toml b/config/default.toml index e31cef4e..8a05517a 100644 --- a/config/default.toml +++ b/config/default.toml @@ -61,6 +61,16 @@ level="verbose" port=3000 # HTTP interface to listen on host="0.0.0.0" +# Enable HTTPS +https=false +# HTTPS certificate file name +cert="cert.pem" +# HTTPS certificate private key file name +key="key.pem" +# HTTPS ca certificate file name +#ca="ca-certificate.pem" +# HTTPS Diffie Hellman parameters (generate with openssl dhparam) +#dhparams="dhparams.pem" # Secret for signing the session ID cookie secret="a cat" # Session length in seconds when "remember me" is checked diff --git a/index.js b/index.js index 305ec2ad..f2a0aaf5 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,8 @@ const config = require('config'); const log = require('npmlog'); const app = require('./app'); const http = require('http'); +const https = require('https'); +const fs = require('fs'); const fork = require('child_process').fork; const triggers = require('./services/triggers'); const importer = require('./services/importer'); @@ -33,10 +35,15 @@ log.level = config.log.level; app.set('port', port); /** - * Create HTTP server. + * Create HTTP/HTTPS server. */ -let server = http.createServer(app); +let server = (!config.www.https) ? http.createServer(app) : https.createServer({ + cert: fs.readFileSync(config.www.cert), + key: fs.readFileSync(config.www.key), + ca: fs.readFileSync(config.www.ca), + dhparams: fs.readFileSync(config.www.dhparams) +}, app); // Check if database needs upgrading before starting the server dbcheck(err => { From abd788d8f4d18b5a977226ba1224cba7f2b7fa9b Mon Sep 17 00:00:00 2001 From: Adrian Woeltche Date: Thu, 21 Jun 2018 16:45:18 +0200 Subject: [PATCH 2/2] optional ca and dhparams --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f2a0aaf5..9428aaf4 100644 --- a/index.js +++ b/index.js @@ -41,8 +41,8 @@ app.set('port', port); let server = (!config.www.https) ? http.createServer(app) : https.createServer({ cert: fs.readFileSync(config.www.cert), key: fs.readFileSync(config.www.key), - ca: fs.readFileSync(config.www.ca), - dhparams: fs.readFileSync(config.www.dhparams) + ca: config.www.ca ? fs.readFileSync(config.www.ca) : undefined, + dhparams: config.www.dhparams ? fs.readFileSync(config.www.dhparams) : undefined }, app); // Check if database needs upgrading before starting the server