This repository has been archived by the owner on Aug 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (50 loc) · 1.48 KB
/
server.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*************************************
//
// averagelanguageoftwitter app
//
**************************************/
// express magic
require('newrelic');
var express = require('express');
var app = express();
var server = require('http').createServer(app)
var io = require('socket.io').listen(server);
io.set('log level', 0); // reduce logging
var device = require('express-device');
var twitter = require('./twitter.js');
var currentSummary;
twitter.getTweets(function(updateData){
console.log('server tweet update');
});
setInterval(function(){
console.log('getting summary');
twitter.getSummary(function(summary){
console.log('summary ',summary.length,' \n ');
io.sockets.emit('update', summary);
currentSummary = summary;
});
}, 5000);
var runningPortNumber = process.env.PORT;
app.configure(function(){
// I need to access everything in '/public' directly
app.use(express.static(__dirname + '/public'));
//set the view engine
app.set('view engine', 'ejs');
app.set('views', __dirname +'/views');
app.use(device.capture());
});
// logs every request
app.use(function(req, res, next){
// output every request in the array
console.log({method:req.method, url: req.url, device: req.device});
// goes onto the next function in line
next();
});
app.get("/", function(req, res){
res.render('index', {});
});
io.sockets.on('connection', function (socket) {
console.log('socket io connected');
io.sockets.emit('update', currentSummary);
});
server.listen(runningPortNumber);