General code sanity, Add some comments and rename ascii.lol to ascii.txt since it is not LOLCODE
This commit is contained in:
parent
532aeb801a
commit
07cf7cbe2d
4 changed files with 46 additions and 43 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
config/config.json
|
config/config.json
|
||||||
|
utils/
|
81
index.js
81
index.js
|
@ -1,52 +1,51 @@
|
||||||
let dE = new Date();
|
const express = require("express"), app = express(), fs = require("fs"), chalk = require("chalk"), config = require("./config/config.json"), emoji = require("./misc/emoji_list.json"),
|
||||||
var startTime = dE.getTime();
|
internals = {
|
||||||
var endTime;
|
|
||||||
|
|
||||||
const express = require("express"),
|
|
||||||
app = express(),
|
|
||||||
fs = require("fs"),
|
|
||||||
chalk = require("chalk"),
|
|
||||||
config = require("./config/config.json");
|
|
||||||
let modules = {};
|
|
||||||
console.clear();
|
|
||||||
|
|
||||||
fs.readFile('./misc/ascii.lol', function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
let asciiOut = data.toString()
|
|
||||||
.replace("|replaceVersion|", `${chalk.yellow("Version:")} ${chalk.cyan(internals.version)}`)
|
|
||||||
.replace("|titlecard|", chalk.yellow("The web server made for EUS"))
|
|
||||||
.replace("DEV", chalk.red("DEV")).replace("RELEASE", chalk.green("RELEASE"))
|
|
||||||
.replace("|replaceType|", `${chalk.yellow("Type: ")}${chalk.cyan(config.server.instance_type)}`);
|
|
||||||
console.log(asciiOut);
|
|
||||||
fs.readdir("./modules", (err, files) => {
|
|
||||||
for (var i = 0; i < files.length; i++) {
|
|
||||||
modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`);
|
|
||||||
console.log(`[Modules] Found module ${files[i].toString()}`)
|
|
||||||
}
|
|
||||||
modules.logger.log(internals.types.a, emoji.wave, "Starting Revolution...");
|
|
||||||
server();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const emoji = require("./misc/emoji_list.json");
|
|
||||||
const internals = {
|
|
||||||
version:"0.0.4 RELEASE",
|
version:"0.0.4 RELEASE",
|
||||||
instance:"Dev Instance", //Deprecated, does absolutely nothing.
|
|
||||||
types: {
|
types: {
|
||||||
a:"INFO",
|
a:"INFO",
|
||||||
b:"REQUEST",
|
b:"REQUEST",
|
||||||
c:"WARN"
|
c:"WARN"
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
let dE = new Date(), startTime = dE.getTime(), endTime, modules = [];
|
||||||
|
|
||||||
|
// Clear console before printing anything
|
||||||
|
console.clear();
|
||||||
|
|
||||||
|
fs.readFile('./misc/ascii.txt', function(err, data) {
|
||||||
|
if (err) throw err;
|
||||||
|
// Generate the banner
|
||||||
|
let asciiOut = data.toString()
|
||||||
|
.replace("|replaceVersion|", `${chalk.yellow("Version:")} ${chalk.cyan(internals.version)}`)
|
||||||
|
.replace("|titlecard|", chalk.yellow("The web server made for EUS"))
|
||||||
|
.replace("DEV", chalk.red("DEV")).replace("RELEASE", chalk.green("RELEASE"))
|
||||||
|
.replace("|replaceType|", `${chalk.yellow("Type: ")}${chalk.cyan(config.server.instance_type)}`);
|
||||||
|
// Print the banner
|
||||||
|
console.log(asciiOut);
|
||||||
|
// Get the modules from the ./modules folder
|
||||||
|
fs.readdir("./modules", (err, files) => {
|
||||||
|
if (err) throw err;
|
||||||
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
/*
|
||||||
|
For every file in the array, output that it was found
|
||||||
|
in the console and attempt to load it using require.
|
||||||
|
Oh, and check that it has .js in it's file name!
|
||||||
|
*/
|
||||||
|
if (files[i].includes(".js")) {
|
||||||
|
modules[files[i].toString().replace(".js", "")] = require(`./modules/${files[i].toString()}`);
|
||||||
|
console.log(`[Modules] Found module ${files[i].toString()}`);
|
||||||
|
} else {
|
||||||
|
console.log(`[Modules] Found file ${files[i]}. It is not a module.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modules.logger.log(internals.types.a, emoji.wave, "Starting Revolution...");
|
||||||
|
server();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function server() {
|
function server() {
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => { modules.request_handler.handle(modules, internals, emoji, req, res); });
|
||||||
modules.request_handler.handle(modules, internals, emoji, req, res);
|
app.listen(config.server.port, () => { dE = new Date(), endTime = dE.getTime();
|
||||||
});
|
|
||||||
app.listen(config.server.port, () => {
|
|
||||||
dE = new Date();
|
|
||||||
endTime = dE.getTime();
|
|
||||||
modules.logger.log(internals.types.a, emoji.thumb_up, `Started Revolution on port ${config.server.port}! Took ${endTime - startTime}ms`);
|
modules.logger.log(internals.types.a, emoji.thumb_up, `Started Revolution on port ${config.server.port}! Took ${endTime - startTime}ms`);
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -3,8 +3,11 @@ const fs = require("fs");
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handle:function(modules, internals, emoji, req, res) {
|
handle:function(modules, internals, emoji, req, res) {
|
||||||
/*
|
/*
|
||||||
req - Request from client
|
modules - Modules that are loaded when Revolution starts
|
||||||
res - Response from server
|
internals - Predefined variables, e.g the version and lables like "INFO"
|
||||||
|
emoji - Pretty self explanitory, the list of emojis used in Revolution.
|
||||||
|
req - Request from client
|
||||||
|
res - Response from server
|
||||||
*/
|
*/
|
||||||
res.set("Server-Type", "Revolution");
|
res.set("Server-Type", "Revolution");
|
||||||
if (req.url == "/") {
|
if (req.url == "/") {
|
||||||
|
|
Loading…
Reference in a new issue