-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (26 loc) · 870 Bytes
/
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
const Hapi = require('hapi');
const package = require('./package.json');
const request = require('request');
const qs = require('./qs');
const _ = require('lodash');
if (process.env.DEBUG)
require('request-debug')(request);
const server = module.exports = new Hapi.Server();
server.connection({port: process.env.PORT || 3009 });
server.route({
method: '*',
path: '/{slackMethod*}',
handler: proxy
});
function proxy(req, reply) {
const payload = _.merge({ }, req.payload, req.query);
const headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
};
const slackMethod = req.params.slackMethod;
var baseUrl = process.env.PROXY_ENDPOINT || `https://slack.com/api`;
baseUrl = baseUrl.replace(/\$/,'');
request
.post(`${baseUrl}/${slackMethod}`, { body: qs(payload), headers })
.on('response', reply);
}