2019-08-19 03:37:02 +01:00
|
|
|
const express = require("express"), app = express(), fs = require("fs"), chalk = require("chalk"), config = require("./config/config.json"), emoji = require("./misc/emoji_list.json"),
|
|
|
|
internals = {
|
|
|
|
version:"0.0.4 RELEASE",
|
|
|
|
types: {
|
|
|
|
a:"INFO",
|
|
|
|
b:"REQUEST",
|
|
|
|
c:"WARN"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let dE = new Date(), startTime = dE.getTime(), endTime, modules = [];
|
2019-08-17 23:33:00 +01:00
|
|
|
|
2019-08-19 03:37:02 +01:00
|
|
|
// Clear console before printing anything
|
2019-08-17 23:33:00 +01:00
|
|
|
console.clear();
|
|
|
|
|
2019-08-19 03:37:02 +01:00
|
|
|
fs.readFile('./misc/ascii.txt', function(err, data) {
|
|
|
|
if (err) throw err;
|
|
|
|
// Generate the banner
|
2019-08-17 23:33:00 +01:00
|
|
|
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)}`);
|
2019-08-19 03:37:02 +01:00
|
|
|
// Print the banner
|
2019-08-17 23:33:00 +01:00
|
|
|
console.log(asciiOut);
|
2019-08-19 03:37:02 +01:00
|
|
|
// Get the modules from the ./modules folder
|
2019-08-17 23:33:00 +01:00
|
|
|
fs.readdir("./modules", (err, files) => {
|
2019-08-19 03:37:02 +01:00
|
|
|
if (err) throw err;
|
2019-08-17 23:33:00 +01:00
|
|
|
for (var i = 0; i < files.length; i++) {
|
2019-08-19 03:37:02 +01:00
|
|
|
/*
|
|
|
|
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.`)
|
|
|
|
}
|
2019-08-17 23:33:00 +01:00
|
|
|
}
|
|
|
|
modules.logger.log(internals.types.a, emoji.wave, "Starting Revolution...");
|
|
|
|
server();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function server() {
|
2019-08-19 03:37:02 +01:00
|
|
|
app.get('*', (req, res) => { modules.request_handler.handle(modules, internals, emoji, req, res); });
|
|
|
|
app.listen(config.server.port, () => { dE = new Date(), endTime = dE.getTime();
|
2019-08-17 23:33:00 +01:00
|
|
|
modules.logger.log(internals.types.a, emoji.thumb_up, `Started Revolution on port ${config.server.port}! Took ${endTime - startTime}ms`);
|
|
|
|
});
|
|
|
|
}
|