-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (28 loc) · 1.04 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
var express = require('express'),
request = require('request'),
bodyParser = require('body-parser'),
app = express(),
appId = process.env.APP_ID;
console.log(appId);
app.use(bodyParser.json());
app.use(express.static(__dirname + '/client'));
app.get('/appid', function(req, res) {
res.send({appId: appId});
});
app.all('*', function (req, res, next) {
var targetURL = req.header('Target-URL');
if (!targetURL) {
res.send(500, { error: 'There is no Target-Endpoint header in the request' });
return;
}
request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },
function (error, response, body) {
if (error) {
console.error('error: ' + response.statusCode)
}
}).pipe(res);
});
app.set('port', process.env.PORT || 8200);
app.listen(app.get('port'), function () {
console.log('Proxy server listening on port ' + app.get('port'));
});