-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.js
86 lines (72 loc) · 2.24 KB
/
receiver.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
let express = require('express'),
app = express(),
bodyParser = require('body-parser'),
request = require('request'),
exportedDatabaseModule = require('./main');
let dataStructure = require('./main');
let parentLevelNode = dataStructure.parentLevelNode;
let currentStats = dataStructure.stats;
let currentNode = parentLevelNode;
let currentResults = parentLevelNode.dfs("");
// Body Parser config
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get("/currentNode", (req, res) => {
res.send(currentNode);
});
app.get("/getCurrentResults", (req, res) => {
res.send(currentResults);
})
app.post("/sendData", (req, res) => {
// console.log(req.body.message.createtextP);
var rs;
for (var x in req.body.message) {
if (req.body.message.hasOwnProperty(x)) {
rs = x.split(",");
console.log(rs[0]+","+rs[1]+","+rs[2]);
// Value: propMap[x]
}
}
let action = rs[0];
//let text = JSON.parse(req.body);
// console.log( Object.keys(req.body)[0]);
// console.log(text);
switch (action) {
case 'create':
let type = rs[1];
let name = rs[2];
// res.send(parentLevelNode);
// add to database
currentNode.addInnerNode(type, name, currentStats);
// // carry out dfs and update
currentResults = parentLevelNode.dfs("");
// res.send(currentResults);
// // render
var options = {
uri: 'http://localhost:3000/newData',
method: 'POST',
json: {
"message": currentResults
}
}
request(options, function(error, response, body) {
if(!error && response.statusCode === 200) {
res.send("Successfully added new data");
}
});
break;
case 'select':
break;
case 'modify':
break;
case 'publish':
break;
default:
console.log("default");
}
});
app.post("/random", (req, res) => {
});
app.listen(3001, () => {
console.log("Receiving server listening on port 3001");
});