-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (40 loc) · 1.43 KB
/
app.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
var express = require('express'),
app = express.createServer(),
io = require('socket.io').listen(app),
request = require('request'),
port = process.env.PORT || 5000;
// Config
io.configure(function () {
io.set('transports', ['xhr-polling']);
io.set('polling duration', 10);
});
app.configure(function(){
app.use(express.bodyParser());
app.use('/static', express.static(__dirname + '/static'));
});
// Start Server
app.listen(port);
// Helpers
var getMessageUrl = function(data) {
var name = data.commits[0].author.name === 'Mjumbe Wawatu Poe' ? 'joo mbay poe' : data.commits[0].author.name,
message = name + ' pushed ' + data.commits.length +
(data.commits.length > 1 ? ' commits' : ' commit') + ' to ' + data.repository.name;
return 'http://translate.google.com/translate_tts?tl=en&q=' + encodeURI(message);
};
var getCoderSoundUrl = function(sounds, data) {
return sounds[data.commits[0].author.username] || sounds['default'];
};
// Routes
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.post('/', function (req, res) {
var payload = JSON.parse(req.body.payload);
request('https://raw.github.com/openplans/ponyexpress/master/sounds.json', function(error, response, body) {
io.sockets.emit('commit', {
'messageUrl': getMessageUrl(payload),
'coderSoundUrl': getCoderSoundUrl(JSON.parse(body), payload)
});
});
res.send('thanks github!');
});