forked from surya-kanoria/DUS-Sample-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (55 loc) · 1.75 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var express = require('express')
var bodyParser = require('body-parser');
var updateGraphs = {};
var components = {};
var app = express();
app.use(bodyParser.json({limit: '50mb'}));
app.get('/updateGraph', function (req, res) {
console.log(updateGraphs);
var appVersion = req.query["appVersion"];
if (updateGraphs[appVersion]) {
var updateGraph = updateGraphs[appVersion];
var responseBody = {
updateGraph: updateGraph
};
res.send(JSON.stringify(responseBody));
} else {
res.sendStatus(204);
}
});
app.post('/getComponents', function (req, res) {
var body = req.body;
var componentsRequested = body.components;
if (!componentsRequested) {
res.sendStatus(400);
} else {
var componentsFetched = {};
componentsRequested.forEach(function (componentKey) {
if (components[componentKey]) {
componentsFetched[componentKey]=components[componentKey];
}
});
var responseBody = {
components: componentsFetched
};
res.send(JSON.stringify(responseBody));
}
});
app.post('/addComponents', function (req, res) {
var body = req.body;
var componentsAdded = body.components;
components = Object.assign({}, components, componentsAdded);
res.sendStatus(200);
});
app.post('/updateGraph', function (req, res) {
var appVersion = req.query["appVersion"];
var body = req.body;
console.log(req.body);
updateGraphs[appVersion] = body.updateGraph;
res.sendStatus(200);
});
var server = app.listen(process.env.PORT || 8080, function () {
// var host = server.address().address;
var port = server.address().port;
console.log('Server listening on port %s', port);
});