-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (51 loc) · 1.52 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
51
52
53
54
55
56
var express = require('express');
var https = require('https');
var fs = require('fs');
var bodyParser = require('body-parser');
// Services
var SubRouter = require('./services/subRouter');
// Set up server
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
// Default server test
app.get('/', function(req, res){
console.log('GET /');
res.send('Success! Server is up.');
});
// Route for Slack post
app.post('/remote', function (req, res) {
console.log('POST /remote');
requestData = req.body;
request = requestData.text;
var credentials = {
userName: requestData.user_name,
userId: requestData.user_id,
teamId: requestData.team_id,
slackToken: requestData.token,
responseUrl: requestData.response_url
};
var subRouter = new SubRouter(request, credentials, function(result){
if (result.errors){
res.send(result.errors.join("\n"));
}
else {
res.send('Success: ' + result.message + "\n");
}
});
});
var httpsPort = process.env.HTTPSPORT || 443;
var key_path = process.env.SSL_PRIVATE_KEY;
var cert_path = process.env.SSL_CERT;
var ca_path = process.env.SSL_CHAIN;
if (ca_path && cert_path && key_path){
var credentials = {
key: fs.readFileSync(key_path),
cert: fs.readFileSync(cert_path),
ca: fs.readFileSync(ca_path)
};
console.log('Found SSL settings. Listening on port ' + httpsPort + '...');
https.createServer(credentials, app).listen(httpsPort);
}
else {
console.log('Could not find SSL Credentials. Please check your configuration.');
}