-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
34 lines (27 loc) · 869 Bytes
/
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
var app = require('express')(),
server = require('http').createServer(app),
fs = require('fs'),
io = require('socket.io').listen(server);
server.listen(3001);
var happen = fs.readFileSync(__dirname + '/happen.js', 'utf8');
function host(req) {
return '//' + req.host + ':' + 3001;
}
app.get('/', function(req, res) {
fs.readFile(__dirname + '/index.html', 'utf8', function(err, f) {
res.send(f.replace('{abs}', host(req)));
});
});
app.get('/anim.gif', function(req, res) {
res.sendfile(__dirname + '/anim.gif');
});
app.get('/receive.js', function(req, res) {
fs.readFile(__dirname + '/receive.js', 'utf8', function(err, f) {
res.send(f.replace('{abs}', host(req)));
});
});
io.sockets.on('connection', function(socket) {
socket.on('send', function(data) {
socket.broadcast.emit('receive', data);
});
});