From 63e1363dd2722109d98db2c8f859fe976351c1be Mon Sep 17 00:00:00 2001 From: Erik Roemmelt Date: Sat, 9 Feb 2019 19:53:40 +0100 Subject: [PATCH] Minor Fixes: Added {useNewUrlParser} fix deprecated warning, suppress some console.log output --- server.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index 5dbd36d..9e2f3b0 100644 --- a/server.js +++ b/server.js @@ -93,7 +93,7 @@ const mongoose = require('mongoose'); mongoose.Promise = global.Promise; // Connecting to the database -mongoose.connect(dbConfig.url) +mongoose.connect(dbConfig.url, {useNewUrlParser: true}) .then(() => { console.log("Successfully connected to MongoDB."); }).catch(err => { @@ -230,20 +230,23 @@ http.createServer (app) .listen (http_port, function () { var options; try { try { - // In case it's a real certificate: add CA chain cersts (TODO: use array if required) - var ca = fs.readFileSync ('keys/ca_cert.pem'); + // In case it's a real certificate: add CA chain cersts (TODO: use array if required) + var ca = fs.readFileSync ('keys/ca_cert.pem'); } catch (e) { - ca = undefined; - console.log ("Note: Can't read CA bundle: "+e); + ca = undefined; + console.log ("Note: Can't read CA bundle: "+e); } - options = { - key: fs.readFileSync ('keys/omkey.pem'), - cert: fs.readFileSync ('keys/certificate.pem'), - ca: ca - }; - https.createServer (options, app) .listen (https_port, function () { - console.log ("Express https server listening on port " + https_port); - }); + if (ca != null) { + + options = { + key: fs.readFileSync ('keys/omkey.pem'), + cert: fs.readFileSync ('keys/certificate.pem'), + ca: ca + }; + https.createServer (options, app) .listen (https_port, function () { + console.log ("Express https server listening on port " + https_port); + }); + } } catch (e) { console.log ("Note: Can't read SSL keys/certs: "+e+"\nDisabling https server"); }