-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
54 lines (44 loc) · 1.33 KB
/
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
45
46
47
48
49
50
51
52
53
54
var browserify = require('browserify-middleware');
var mustache = require('mustache-express');
var express = require('express');
var app = express();
var port = process.env.WEPLAY_PORT || 3000;
var redis = require('./redis')();
process.title = 'weplay-web';
app.listen(port);
console.log('listening on *:' + port);
app.engine('mustache', mustache());
app.set('views', __dirname + '/views');
if ('development' == process.env.NODE_ENV) {
app.use('/main.js', browserify('./client/app.js'));
}
app.use(express.static(__dirname + '/public'));
app.use(function(req, res, next){
req.socket.on('error', function(err){
console.error(err.stack);
});
next();
});
var url = process.env.WEPLAY_IO_URL || 'http://localhost:3001';
app.get('/', function(req, res, next){
redis.get('weplay:frame', function(err, image){
if (err) return next(err);
redis.get('weplay:connections-total', function(err, count){
if (err) return next(err);
res.render('index.mustache', {
img: image.toString('base64'),
io: url,
connections: count
});
});
});
});
app.get('/screenshot.png', function(req, res, next) {
redis.get('weplay:frame', function(err, image){
if (err) return next(err);
res.writeHead(200, {
'Content-Type':'image/png',
'Content-Length': image.length});
res.end(image);
});
});