Check if SSL key and certificate files exist

This commit is contained in:
toXel 2016-10-05 00:35:04 +02:00
parent cd87df955e
commit 5b6f5d5dce

View File

@ -36,9 +36,19 @@ module.exports = function() {
server = server.createServer(app).listen(config.port, config.host); server = server.createServer(app).listen(config.port, config.host);
} else { } else {
server = require("spdy"); 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({ server = server.createServer({
key: fs.readFileSync(Helper.expandHome(config.https.key)), key: fs.readFileSync(keyPath),
cert: fs.readFileSync(Helper.expandHome(config.https.certificate)) cert: fs.readFileSync(certPath)
}, app).listen(config.port, config.host); }, app).listen(config.port, config.host);
} }