forked from PoJo93/god-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (36 loc) · 1014 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Imports
var express = require('express');
var http = require('http');
var socketIo = require('socket.io');
var Poll = require('./poll.js');
// routes
var routes = require('./routes/index');
var polls = {};
// Create Server
var app = express();
var server = http.Server(app);
var io = socketIo(server); // Websockets
polls['blah'] = new Poll();
polls['blah'].add('Test 1');
polls['blah'].add('Test 2');
polls['blah'].increment(0);
polls['blah'].increment(0);
polls['blah'].increment(1);
io.on('connection', function(socket) {
socket.on('request-data', function(id) {
socket.emit('poll-data', polls[id].data);
});
socket.on('request-labels', function(id) {
var data = polls[id].data;
socket.emit('poll-labels', {
labels: data.labels,
question: 'Blah blah'
});
});
});
app.use(express.static(__dirname + '/public'));
var port = process.env.PORT || 8000; // Get server port
server.listen(port, function() {
// Start Server and print it
console.log('Server started on port', port);
});