From 5b6f5d5dcef869abc5d88403632ad51e547f7a2c Mon Sep 17 00:00:00 2001 From: toXel Date: Wed, 5 Oct 2016 00:35:04 +0200 Subject: [PATCH] Check if SSL key and certificate files exist --- src/server.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index 95ec2e9e..980b68a4 100644 --- a/src/server.js +++ b/src/server.js @@ -36,9 +36,19 @@ module.exports = function() { server = server.createServer(app).listen(config.port, config.host); } else { server = require("spdy"); + const keyPath = Helper.expandHome(config.https.key); + const certPath = Helper.expandHome(config.https.certificate); + if (!config.https.key.length || !fs.existsSync(keyPath)) { + log.error("Path to SSL key is invalid. Stopping server..."); + process.exit(); + } + if (!config.https.certificate.length || !fs.existsSync(certPath)) { + log.error("Path to SSL certificate is invalid. Stopping server..."); + process.exit(); + } server = server.createServer({ - key: fs.readFileSync(Helper.expandHome(config.https.key)), - cert: fs.readFileSync(Helper.expandHome(config.https.certificate)) + key: fs.readFileSync(keyPath), + cert: fs.readFileSync(certPath) }, app).listen(config.port, config.host); }