Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rabadons Application Entry Point
- const fs = require("fs");
- const cluster = require("cluster");
- const os = require("os");
- if (cluster.isMaster) {
- // Fork the workers on launch.
- for (let i = 0; i < os.cpus().length; i++) cluster.fork();
- console.log(`Application forked ${os.cpus().length} workers.`);
- } else {
- // Application logic.
- const Chronograph = require("./classes/Chronograph");
- const path = require("path");
- const fs = require("fs");
- const requestjs = require("request");
- const mysql = require("mysql");
- const express = require("express");
- const bodyparser = require("body-parser");
- const application = express();
- const Framework = require("./classes/Framework")();
- // Configure MySQL
- var connection = mysql.createConnection({
- host: "localhost",
- user: "rabmaster",
- password: "XLJ_MES",
- database: "rab"
- });
- //connection.connect();
- // Application Runtime Settings
- application.set("view engine", "ejs");
- application.use("/public/", express.static("public/"));
- // Framework Runtime Settings
- Framework.set("stylesheets", "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"); // Font Awesome
- Framework.set("stylesheets", "/public/css/bulma.css"); // Bulma Framework
- Framework.set("stylesheets", "/public/css/main.css"); // Customization CSS
- Framework.set("scripts", "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.js"); // Chart JS
- Framework.set("scripts", "/public/js/main.js"); // Customization JS
- // Body Parser
- application.use(bodyparser.json());
- application.use(bodyparser.urlencoded({extended: true}));
- // API KEY
- const API_KEY = "?api_key=RGAPI-d04f7a25-f625-4919-a308-aba01758feb9"
- /*
- * WEB SERVER CODE BEGINS HERE
- * ---------------------------
- * Currently added:
- * /index
- * Contains the homepage and access to all the other features of the website.
- * /summoner
- * Servers as a redirect to /summoner/:summonerName when given a post request.
- * If the page is a simple get request, it prompts the user to enter a username.
- * /summoner/:summonerName
- * Serves up the information for a user otherwise serves up a "user not found".
- *
- * 221589789 MAGIK TRIK ACCOUNT ID
- *
- *
- *
- */
- // GET /index
- application.get("/", function(request, response) {
- var index = Framework.create();
- index.head.title = "Rabadon's Homepage";
- response.render("index", index, (error, html) => {
- if (error) {
- response.render("errors/error_500", {}, (error, html) => {
- response.status(500).send(html);
- });
- } else response.send(html);
- });
- });
- // GET-POST /summoner
- application.route("/summoner")
- .post((request, response) => {
- // Exchanges post to get and redirects.
- var summonerName = request.body.summonerName.split(" ").join("%20");
- response.redirect("/summoner/"+summonerName);
- })
- .get((request, response) => {
- var summonerPage = Framework.create();
- summonerPage.head.title = "Rabadon's Analytics";
- summonerPage.meta.status = "search";
- response.render("summoner", summonerPage, (error, html) => {
- if (error) {
- response.render("errors/error_500", {}, (error, html) => {
- response.status(500).send(html);
- })
- } else response.send(html);
- });
- });
- // GET /summoner/:summonerName
- application.get("/summoner/:summonerName", (request, response) => {
- var summonerPage = Framework.create();
- summonerPage.head.title = "Rabadon's Analytics";
- fs.readFile("./assets/matchex.json", (error, data) => {
- var match = JSON.parse(data);
- // Get the teams.
- var redTeam = [];
- var blueTeam = [];
- for (let i = 0; i < match.participants.length; i++) {
- if (match.participants[i].teamId == 100) {
- match.participantIdentities[match.participants[i].participantId]
- } else {
- }
- }
- })
- });
- // Catch any pages that don't exist if it has falled through all the pieces above.
- application.use((request, response) => {
- response.render("errors/error_404", {}, (error, html) => {
- response.status(404).send(html);
- });
- });
- application.listen(80);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement