From a958584b0be1e1e64821ba22aa428e23c4041976 Mon Sep 17 00:00:00 2001 From: Ethan Stubbs Date: Mon, 30 Dec 2019 07:39:32 +0000 Subject: [PATCH 1/2] Add "Setup" header --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index c823dc0..e6286b9 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,6 @@

Revolution is a web server that I designed to be flexible to fit the needs of it's applications.

It is mainly used in my Screenshot server, EUS which was recently rewriten.

It's main design goal was to be modular.

+

+ Setup +

-- 2.47.0 From 875e043186a81126d44ddaf76b2c1fd78f816f1a Mon Sep 17 00:00:00 2001 From: tgpethan Date: Thu, 2 Jan 2020 20:44:05 +0000 Subject: [PATCH 2/2] Add required module checks Checks for modules that are required by the server before startup. --- index.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e09ce3f..c4c4e8f 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,15 @@ fs = require("fs"), chalk = require("chalk"), config = require("./config/config.json"), emoji = require("./misc/emoji_list.json"); +class reqMod { + constructor(name, status) { + this.name = name; + this.status = status; + } +} +const requiredModules = [ + new reqMod("handle_console", false) +]; global.actualDir = __dirname; global.internals = { version:"Open Source", @@ -34,6 +43,12 @@ fs.readFile('./misc/ascii.txt', function(err, data) { 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()}`); + // Loop through and set the required modules flags + for (var i1 = 0; i1 < requiredModules.length; i1++) { + if (global.modules[files[i].toString().replace(".js", "")].MOD_FUNC == requiredModules[i1].name) { + requiredModules[i1].status = true; + } + } // We want to find out what the request handler module is if (global.modules[files[i].toString().replace(".js", "")].MOD_FUNC == "handle_requests") { // Set reqhandler to the request handler for easy getting @@ -48,8 +63,22 @@ fs.readFile('./misc/ascii.txt', function(err, data) { console.log(chalk.bgRed(` ! [Modules] ${err} ! `)); } } - global.modules.consoleHelper.printInfo(emoji.wave, "Starting Revolution..."); - server(); + // Check if all the required modules flags are set + let allRequiredExist = []; + for (var i = 0; i < requiredModules.length; i++) { + if (requiredModules[i].status) { + allRequiredExist.push(true); + } + } + if (allRequiredExist.length !== requiredModules.length) { + // Exit if all required modules are not found + 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 { + global.modules.consoleHelper.printInfo(emoji.wave, "Starting Revolution..."); + server(); + } }); }); -- 2.47.0