diff --git a/index.js b/index.js index e7c50c5..9219dd4 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,15 @@ const requiredModules = [ new reqMod("handle_console", false) ]; let config; +// Statup so sync stuff is fine +// Check if config exists if (fs.existsSync("./config/config.json")) { + // It exists, load it. config = JSON.parse(fs.readFileSync("./config/config.json")); } else { console.log("[Config] Config file doesn't exist! You probably haven't copied the example config in the config directory."); console.log("[Config] Exiting..."); + // It doesn't exist, exit the framework and tell the user what to do process.exit(1); } global.actualDir = __dirname; @@ -26,6 +30,7 @@ global.internals = { global.app = express(); global.modules = []; let dE = new Date(), +// Get the time at invocation startTime = dE.getTime(), endTime, reqhandler; @@ -33,6 +38,7 @@ reqhandler; // Clear console before printing anything console.clear(); +// Read the server header for output fs.readFile('./misc/ascii.txt', function(err, data) { if (err) throw err; // Generate and Print the banner @@ -47,6 +53,7 @@ fs.readFile('./misc/ascii.txt', function(err, data) { Oh, and check that it has .js in it's file name! */ try { + // Make sure the file has the extention of .js if (files[i].includes(".js")) { console.log(`[Modules] Found module ${files[i].toString()}`); global.modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`); @@ -73,14 +80,17 @@ fs.readFile('./misc/ascii.txt', function(err, data) { // Check if all the required modules flags are set let allRequiredExist = []; for (var i = 0; i < requiredModules.length; i++) { + // Push the status of the required modules to an array allRequiredExist.push(requiredModules[i].status); } + // Make sure all required modules are found if (allRequiredExist.length !== requiredModules.length) { - // Exit if all required modules are not found + // They are not all found, exit framework with code 1. console.log("[Modules] All required modules could not be found."); console.log("[Modules] Server will not start until all required modules are found."); process.exit(1); } else { + // All required modules are found, start the framework's server. global.modules.consoleHelper.printInfo(emoji.wave, "Starting Revolution..."); server(); } @@ -88,11 +98,16 @@ fs.readFile('./misc/ascii.txt', function(err, data) { }); function server() { + // Load in the request handler's extra required items. reqhandler.extras(); + // Define where GET requests go to in the request handlers. app.get('*', (req, res) => reqhandler.get(req, res)); + // Define where POST requests go to in the request handlers. app.post('*', (req, res) => reqhandler.post(req, res)); + // Start the server listening at the port defined in the config file app.listen(config.server.port, () => { dE = new Date(), + // Get time after server has started listening or the "end time". endTime = dE.getTime(); global.modules.consoleHelper.printInfo(emoji.thumb_up, `Started Revolution on port ${config.server.port}! Took ${endTime - startTime}ms`); });