From 4e85c8f9e32d556e0f8682f9ecbae1e4a8bf49e6 Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 6 Apr 2017 17:23:10 +0200 Subject: support cruncher --- index.html | 29 +++++++++++++++++++++++++++++ server.js | 15 +++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/index.html b/index.html index e542138..f12c585 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,23 @@

+

+

+
+ + +
+
+ + +
+
+ + +
+ +
+

@@ -82,6 +99,18 @@ subscribe(resp.name); }); }); + + $("#crunch-form").submit((e) => { + e.preventDefault(); + let dimension_on = $("#crunch-on").val(), + data = {}; + data[$("#crunch-filter").val()] = $("#crunch-value").val(); + $.ajax("/api/stats/" + dimension_on + "/update", { + data: JSON.stringify(data), + contentType: "application/json", + type: "POST" + }); + }); diff --git a/server.js b/server.js index ec7e3d0..c921d00 100644 --- a/server.js +++ b/server.js @@ -5,6 +5,7 @@ var amqp = require("amqplib"), Seq = require("sequelize"), request = require("request-promise"), express = require("express"), + bodyParser = require("body-parser"), http = require("http"), sleep = require("sleep-promise"); @@ -38,6 +39,7 @@ var rabbit, ch, seq, server.listen(8880); app.use(express.static("assets")); +app.use(bodyParser.json()); // request a grab job function requestUpdate(name, region, last_match_created_date, id) { @@ -158,6 +160,19 @@ app.post("/api/player", async (req, res) => { res.json(player); }); +// crunch data +app.post("/api/stats/:dimension_on/update", async (req, res) => { + // forward JSON + let payload = { + dimension_on: req.params.dimension_on, + filter: req.body + }; + console.log(payload); + await ch.sendToQueue("crunch", new Buffer(JSON.stringify(payload)), + { persistent: true }); + res.sendStatus(204); +}); + /* internal monitoring */ app.get("/", (req, res) => { res.sendFile(__dirname + "/index.html"); -- cgit v1.3.1