Added error handling for HTTPS key/cert file loading.

This commit is contained in:
rainbow napkin 2025-04-12 06:16:38 -04:00
parent 069cb423fd
commit 401b9e4fee

View file

@ -91,6 +91,7 @@ let webServer = null;
//If we're using HTTPS //If we're using HTTPS
if(config.protocol.toLowerCase() == "https"){ if(config.protocol.toLowerCase() == "https"){
try{
//Read key/cert files and store contents //Read key/cert files and store contents
const httpsOptions = { const httpsOptions = {
key: fs.readFileSync(config.ssl.key), key: fs.readFileSync(config.ssl.key),
@ -98,6 +99,15 @@ if(config.protocol.toLowerCase() == "https"){
}; };
webServer = https.createServer(httpsOptions, app); webServer = https.createServer(httpsOptions, app);
}catch(err){
if(err.path != null && err.path != ""){
console.log(`Error opening key/cert file: ${err.path}`);
}else{
console.log("Unknown error occured while starting HTTPS server! Bailing out!");
console.log(err);
}
process.exit();
}
//Otherwise //Otherwise
}else{ }else{