Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Rabadons Application Entry Point
  2. const fs = require("fs");
  3. const cluster = require("cluster");
  4. const os = require("os");
  5.  
  6. if (cluster.isMaster) {
  7.  
  8.     // Fork the workers on launch.
  9.     for (let i = 0; i < os.cpus().length; i++) cluster.fork();
  10.     console.log(`Application forked ${os.cpus().length} workers.`);
  11.  
  12. } else {
  13.  
  14.     // Application logic.
  15.     const Chronograph = require("./classes/Chronograph");
  16.     const path = require("path");
  17.     const fs = require("fs");
  18.     const requestjs = require("request");
  19.     const mysql = require("mysql");
  20.     const express = require("express");
  21.     const bodyparser = require("body-parser");
  22.     const application = express();
  23.     const Framework = require("./classes/Framework")();
  24.  
  25.     // Configure MySQL
  26.     var connection = mysql.createConnection({
  27.         host: "localhost",
  28.         user: "rabmaster",
  29.         password: "XLJ_MES",
  30.         database: "rab"
  31.     });
  32.  
  33.     //connection.connect();
  34.  
  35.     // Application Runtime Settings
  36.     application.set("view engine", "ejs");
  37.     application.use("/public/", express.static("public/"));
  38.  
  39.     // Framework Runtime Settings
  40.     Framework.set("stylesheets", "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"); // Font Awesome
  41.     Framework.set("stylesheets", "/public/css/bulma.css");              // Bulma Framework
  42.     Framework.set("stylesheets", "/public/css/main.css");               // Customization CSS
  43.  
  44.     Framework.set("scripts", "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.js");   // Chart JS
  45.     Framework.set("scripts", "/public/js/main.js");                     // Customization JS
  46.  
  47.     // Body Parser
  48.     application.use(bodyparser.json());
  49.     application.use(bodyparser.urlencoded({extended: true}));
  50.  
  51.     // API KEY
  52.     const API_KEY = "?api_key=RGAPI-d04f7a25-f625-4919-a308-aba01758feb9"
  53.  
  54.  
  55.  
  56.  
  57.     /*
  58.      * WEB SERVER CODE BEGINS HERE
  59.      * ---------------------------
  60.      * Currently added:
  61.      * /index
  62.      *      Contains the homepage and access to all the other features of the website.
  63.      * /summoner
  64.      *      Servers as a redirect to /summoner/:summonerName when given a post request.
  65.      *      If the page is a simple get request, it prompts the user to enter a username.
  66.      * /summoner/:summonerName
  67.      *      Serves up the information for a user otherwise serves up a "user not found".
  68.      *
  69.      * 221589789 MAGIK TRIK ACCOUNT ID
  70.      *
  71.      *
  72.      *
  73.     */
  74.  
  75.     // GET /index
  76.     application.get("/", function(request, response) {
  77.         var index = Framework.create();
  78.         index.head.title = "Rabadon's Homepage";
  79.         response.render("index", index, (error, html) => {
  80.             if (error) {
  81.                 response.render("errors/error_500", {}, (error, html) => {
  82.                     response.status(500).send(html);
  83.                 });
  84.             } else response.send(html);
  85.         });
  86.     });
  87.  
  88.     // GET-POST /summoner
  89.     application.route("/summoner")
  90.  
  91.         .post((request, response) => {
  92.  
  93.             // Exchanges post to get and redirects.
  94.             var summonerName = request.body.summonerName.split(" ").join("%20");
  95.             response.redirect("/summoner/"+summonerName);
  96.  
  97.         })
  98.  
  99.         .get((request, response) => {
  100.  
  101.             var summonerPage = Framework.create();
  102.             summonerPage.head.title = "Rabadon's Analytics";
  103.             summonerPage.meta.status = "search";
  104.             response.render("summoner", summonerPage, (error, html) => {
  105.                 if (error) {
  106.                     response.render("errors/error_500", {}, (error, html) => {
  107.                         response.status(500).send(html);
  108.                     })
  109.                 } else response.send(html);
  110.             });
  111.  
  112.         });
  113.  
  114.     // GET /summoner/:summonerName
  115.     application.get("/summoner/:summonerName", (request, response) => {
  116.  
  117.         var summonerPage = Framework.create();
  118.         summonerPage.head.title = "Rabadon's Analytics";
  119.  
  120.         fs.readFile("./assets/matchex.json", (error, data) => {
  121.  
  122.             var match = JSON.parse(data);
  123.            
  124.             // Get the teams.
  125.  
  126.             var redTeam = [];
  127.             var blueTeam = [];
  128.  
  129.             for (let i = 0; i < match.participants.length; i++) {
  130.                 if (match.participants[i].teamId == 100) {
  131.                     match.participantIdentities[match.participants[i].participantId]
  132.                 } else {
  133.  
  134.                 }
  135.             }
  136.  
  137.  
  138.         })
  139.  
  140.     });
  141.  
  142.     // Catch any pages that don't exist if it has falled through all the pieces above.
  143.     application.use((request, response) => {
  144.         response.render("errors/error_404", {}, (error, html) => {
  145.             response.status(404).send(html);
  146.         });
  147.     });
  148.    
  149.     application.listen(80);
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement