1 | require('dotenv').config(); |
||
2 | var express = require('express'); |
||
3 | var app = express(); |
||
4 | var request = require('request'); |
||
5 | |||
6 | // Create body parsers for application/json and application/x-www-form-urlencoded |
||
7 | var bodyParser = require('body-parser') |
||
8 | app.use(bodyParser.json()) |
||
9 | app.use(bodyParser.urlencoded({ extended: false })) |
||
10 | |||
11 | var useTls = process.env.MY_APP_TLS_ENABLED > 0 ? true : false; |
||
12 | var server = null; |
||
13 | var port = process.env.MY_APP_PORT; |
||
14 | |||
15 | var subscribed = false; |
||
16 | |||
17 | if (useTls) { |
||
18 | var tls = require('tls'), |
||
19 | fs = require('fs'); |
||
20 | server = https.createServer({ |
||
21 | key: fs.readFileSync(process.env.MY_APP_TLS_PRIVATE_KEY), |
||
22 | cert: fs.readFileSync(process.env.MY_APP_TLS_PUBLIC_CERT) |
||
23 | }, app).listen(port, function() { |
||
24 | console.log('LISTEN_HTTPS ' + port); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
25 | }); |
||
26 | } else if (! useTls) { |
||
27 | server = require('http').Server(app); |
||
28 | server.listen(port, function() { |
||
29 | console.log('LISTEN_HTTP ' + port); |
||
0 ignored issues
–
show
|
|||
30 | }); |
||
31 | } |
||
32 | |||
33 | var callback = function(error, normalized) { |
||
34 | var hook = { |
||
35 | icon: normalized.icon, |
||
36 | email: normalized.email, |
||
37 | name: normalized.name, |
||
38 | link: normalized.link, |
||
39 | title: normalized.title, |
||
40 | activity: normalized.activity, |
||
41 | body: normalized.body |
||
42 | }; |
||
43 | |||
44 | request({ |
||
45 | url: 'https://hooks.glip.com/webhook/' + normalized.glipguid, |
||
46 | method: "POST", |
||
47 | json: hook |
||
48 | }); |
||
49 | } |
||
50 | |||
51 | var tc = require('./normalizer_travisci.js'); |
||
52 | |||
53 | app.post('/webhook/travisci/out/glip/:glipguid/?', function(req, res) { |
||
54 | var payload = JSON.parse(req.body.payload); |
||
55 | var options = { glipguid: req.params.glipguid, payload: payload }; |
||
56 | var travisci = new tc.Travisci_Normalizer(); |
||
57 | travisci.normalize(options, callback); |
||
58 | var note = 'Finished Travis CI Webhook Request'; |
||
59 | console.log(note); |
||
0 ignored issues
–
show
|
|||
60 | res.send(note); |
||
61 | }); |
||
62 |