-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
31 lines (23 loc) · 837 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
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io').listen(server);
app.use(express.static('public'));
server.listen(80, function () {
console.log('Nifty server running on port 80!');
});
io.set('transports', ['websocket']);
io.on('connection', function (socket) {
app.get('/cardmatch/:id', function (req, res) {
res.send(req.params.id);
if(isNaN(req.params.id)){
socket.broadcast.emit('card_image', {'auto':true,'src':'http://localhost/cards/'+req.params.id+'.jpg'});
}
else {
socket.broadcast.emit('card_image', {'auto':true,'src':'http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid='+req.params.id+'&type=card'});
}
});
socket.on('card_image', function(msg){
socket.broadcast.emit('card_image', msg);
});
});