-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing_app.js
37 lines (31 loc) · 1.38 KB
/
routing_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
const express = require('express');
const request = require('request');
const bodyParser = require('body-parser');
const fs = require('fs');
const app = express();
app.use(express.json());
app.use(bodyParser.urlencoded({extended: false}));
const addressDetails = JSON.parse(fs.readFileSync('address.json'));
const remote = JSON.parse(fs.readFileSync('ips.json'));
app.post('/slack/actions', function (req, res) {
console.log('[ROUTING APP]: Received http POST from slack, routing to endpoints...');
var info = req.body.payload;
for (var i = 0; i < remote.length; i++) {
var ip = remote[i];
console.log('[' + ip + ']: Sending http POST...')
request.post('http://' + ip + ':5000/slack/actions', {
form: {
payload: info
}
}, function (err, httpResponse, body) {
if(httpResponse) {
console.log('[' + httpResponse.connection.remoteAddress + ']: Received httpStatusCode ' + httpResponse.statusCode)
}
})
}
res.end();
});
app.listen(addressDetails.port, addressDetails.ip, function () {
console.log('[ROUTING APP]: Read %s ips from database: [%s]', remote.length, remote);
console.log('[ROUTING APP]: Starting server on %s:%s', addressDetails.ip, addressDetails.port);
});