|
@ -1,11 +1,18 @@ |
|
|
var express = require('express'); |
|
|
|
|
|
var http = require('http'); |
|
|
|
|
|
var io = require('socket.io'); |
|
|
|
|
|
var bodyParser = require('body-parser'); |
|
|
|
|
|
var cookieParser = require('cookie-parser'); |
|
|
|
|
|
|
|
|
var express = require('express'), |
|
|
|
|
|
http = require('http'), |
|
|
|
|
|
io = require('socket.io'), |
|
|
|
|
|
bodyParser = require('body-parser'), |
|
|
|
|
|
cookieParser = require('cookie-parser'), |
|
|
|
|
|
mongojs = require('mongojs'); |
|
|
|
|
|
|
|
|
var app = express(); |
|
|
var app = express(); |
|
|
app.use(express.static('./public')); |
|
|
app.use(express.static('./public')); |
|
|
|
|
|
|
|
|
|
|
|
var mongoUri = "mongodb://localhost:27017/visualizer"; |
|
|
|
|
|
var db = mongojs( mongoUri ); |
|
|
|
|
|
var honeyCombs = db.collection('honeyCombs'); |
|
|
|
|
|
// honeyCombs.insert({dio: "cane", type: "flyingPig"});
|
|
|
|
|
|
|
|
|
//Specifying the public folder of the server to make the html accesible using the static middleware
|
|
|
//Specifying the public folder of the server to make the html accesible using the static middleware
|
|
|
app.use(cookieParser()); |
|
|
app.use(cookieParser()); |
|
|
|
|
|
|
|
@ -35,6 +42,7 @@ app.post('/show', urlencodedParser, function (req, res) { |
|
|
for(var i in io.sockets.connected) { |
|
|
for(var i in io.sockets.connected) { |
|
|
var socket = io.sockets.connected[i]; |
|
|
var socket = io.sockets.connected[i]; |
|
|
socket.emit("jsonHoneycomb", req.body.honeyComb); |
|
|
socket.emit("jsonHoneycomb", req.body.honeyComb); |
|
|
|
|
|
saveQuery(req.body.honeyComb); |
|
|
} |
|
|
} |
|
|
// var socket = findSocketByCookie(req.cookies.myUniqueCookie);
|
|
|
// var socket = findSocketByCookie(req.cookies.myUniqueCookie);
|
|
|
|
|
|
|
|
@ -68,10 +76,23 @@ io.sockets.on('connection', function(socket){ |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
socket.on('jsonToParse', function(msg){ |
|
|
socket.on('jsonToParse', function(msg){ |
|
|
if(msg == "true"){ |
|
|
|
|
|
console.log('Json received.'); |
|
|
console.log('Json received.'); |
|
|
socket.emit("jsonHoneycomb", msg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
saveQuery(msg); |
|
|
|
|
|
// socket.emit("jsonHoneycomb", msg);
|
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
function saveQuery(query){ |
|
|
|
|
|
var d = new Date(); |
|
|
|
|
|
d = |
|
|
|
|
|
("00" + (d.getMonth() + 1)).slice(-2) + "/" + |
|
|
|
|
|
("00" + d.getDate()).slice(-2) + "/" + |
|
|
|
|
|
d.getFullYear() + " " + |
|
|
|
|
|
("00" + d.getHours()).slice(-2) + ":" + |
|
|
|
|
|
("00" + d.getMinutes()).slice(-2) + ":" + |
|
|
|
|
|
("00" + d.getSeconds()).slice(-2) |
|
|
|
|
|
; |
|
|
|
|
|
console.log("Saving query in db..."); |
|
|
|
|
|
honeyCombs.insert({ honeyComb: query, dateStamp: d }); |
|
|
|
|
|
} |