-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (42 loc) · 1.38 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
const express = require('express');
const path = require('path');
const request = require('request');
const bodyParser = require('body-parser');
const logger = require('morgan');
const app = express();
const config = require('./config');
const port = config.port;
// Log the requests
app.use(logger('dev'));
// Serve static files
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'dist')));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
function userAPI(url, postData, res) {
let clientServerOptions = {
uri: url,
body: JSON.stringify(postData),
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
request(clientServerOptions, function (error, response) {
if (error) throw error;
console.log('aserver response from request', response.body);
res.send(response.body.replace(/^"|"$/g, ''));
});
}
app.post('/proxy', function (req, res) {
let input = req.body;
let path = input.payload.path;
let url = input.payload.url;
let orgname = input.header.ownerName;
let newUrl = 'http://' + url + ':7554/' + path;
console.log("path of request " + newUrl + " to org " + orgname);
userAPI(newUrl, input, res);
});
app.listen(port, function () {
console.log('app listening on port ' + port);
});