-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (57 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
64
65
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var bodyParser = require('body-parser');
var util = require('util');
server.listen(process.env.PORT);
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.get('/', function(request, response) {
response.send('Hello World!');
});
app.post('/on', function(req, resp) {
io.emit('power', 'on');
resp.send('turning on...');
});
app.post('/off', function(req, resp) {
io.emit('power', 'off')
resp.send('turning off...');
});
app.post('/color', function(req, resp) {
var params = req.body;
io.emit('color', params.color);
console.log("Set color to: " + params);
resp.send("Set color to: " + params);
});
app.post('/transition', function(req, resp) {
var params = req.body;
io.emit('transition', params);
var msg = "Transition to " + params.color + " over " + params.timeMs + "ms";
console.log(msg);
resp.send(msg)
})
app.post('/circleci', function(req, resp) {
if(process.env.LOG_LEVEL == 'debug') {
console.log(util.inspect(req.body, {showHidden: false, depth: null}));
}
var params = req.body.payload;
var project = params.username + "/" + params.reponame + "/" + params.branch;
switch (params.outcome) {
case "success":
console.log("Setting success");
io.emit(project, "green");
break;
case "failed":
console.log("Setting failure");
io.emit(project, "red");
break;
default:
break;
}
resp.send("OK")
});
io.on('connection', function(socket){
console.log("New connection.");
});