Updated The App.listen Method to Use Either Http Or Https.

It Still Has All Functions Of Burlone Nothing Else That IT Doesnt
This commit is contained in:
Adrix
2024-10-27 17:12:44 +02:00
committed by GitHub
parent 598098d46d
commit edfd0e2bdc
+58 -18
View File
@@ -21,6 +21,21 @@ global.JWT_SECRET = functions.MakeID();
const PORT = config.port;
const WEBSITEPORT = config.Website.websiteport;
// Check if HTTPS is enabled
let httpsServer;
if (config.bEnableHTTPS) {
const https = require('https'); // Import the https module
// Load SSL certificate options from config
const httpsOptions = {
cert: fs.readFileSync(config.ssl.cert),
ca: fs.existsSync(config.ssl.ca) ? fs.readFileSync(config.ssl.ca) : undefined, // Optional
key: fs.readFileSync(config.ssl.key)
};
httpsServer = https.createServer(httpsOptions, app);
}
if (!fs.existsSync("./ClientSettings")) fs.mkdirSync("./ClientSettings");
global.JWT_SECRET = functions.MakeID();
@@ -107,25 +122,50 @@ app.get("/unknown", (req, res) => {
res.json({ msg: "Reload Backend - Made by Burlone" });
});
app.listen(PORT, () => {
log.backend(`Backend started listening on port ${PORT}`);
// Start the server
const startServer = (server) => {
server.listen(PORT, () => {
log.backend(`Backend started listening on port ${PORT}`);
require("./xmpp/xmpp.js");
if (config.discord.bUseDiscordBot === true) {
require("./DiscordBot");
}
if (config.bUseAutoRotate === true) {
require("./structs/autorotate.js")
}
// Load additional modules
require("./xmpp/xmpp.js");
if (config.discord.bUseDiscordBot === true) {
require("./DiscordBot");
}
if (config.bUseAutoRotate === true) {
require("./structs/autorotate.js");
}
}).on("error", async (err) => {
if (err.code === "EADDRINUSE") {
log.error(`Port ${PORT} is already in use!\nClosing in 3 seconds...`);
await functions.sleep(3000);
process.exit(0);
} else throw err;
});
}).on("error", async (err) => {
if (err.code === "EADDRINUSE") {
log.error(`Port ${PORT} is already in use!\nClosing in 3 seconds...`);
await functions.sleep(3000);
process.exit(0);
} else {
throw err;
}
});
};
// Check if HTTPS is enabled
if (config.bEnableHTTPS) {
const httpsOptions = {
cert: fs.readFileSync(config.ssl.cert),
ca: fs.existsSync(config.ssl.ca) ? fs.readFileSync(config.ssl.ca) : undefined, // Optional
key: fs.readFileSync(config.ssl.key)
};
const httpsServer = https.createServer(httpsOptions, app);
wss = new WebSocket({ server: httpsServer });
// Start the HTTPS server
startServer(httpsServer);
} else {
// Start the HTTP server
wss = new WebSocket({ server: app.listen(PORT) });
startServer(app);
}
if (config.bEnableAutoBackendRestart === true) {
AutoBackendRestart.scheduleRestart(config.bRestartTime);
@@ -169,4 +209,4 @@ function DateAddHours(pdate, number) {
return date;
}
module.exports = app;
module.exports = app;