forked from WCOMAB/KuduPostDeploymentSlackHook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (36 loc) · 1.23 KB
/
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
35
36
37
38
39
40
41
var http = require('http');
var url = require('url');
var slack = require('./slack.js');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
var parsedRequest = parseRequest(req);
req.on('end', function () {
if (!parsedRequest.body || parsedRequest.body == '')
{
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end("WCOM AB - Kudu Post Deployment Slack Hook");
return;
}
slack.sendToSlack(parsedRequest, function(error) {
var result = {
status: 500,
text: "Sorry!\r\n"
};
if (!error) {
result.status = 200;
result.text = "Thanks!";
}
res.writeHead(result.status, { 'Content-Type': 'text/plain' });
res.end(result.text);
})
});
}).listen(port);
function parseRequest(req)
{
var parsedRequest = {
body: '',
channel: url.parse(req.url, true).query.channel
};
req.on('data', function (chunk) { parsedRequest.body += chunk; });
return parsedRequest;
}