-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
89 lines (73 loc) · 1.69 KB
/
controller.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
87
88
89
exports.execute_get = function(req, res, done){
try
{
var method = req.params.controller_method;
if (method == "up")
{
console.log('my status was checked and it is up!');
res.send({status:'up'});
}
}
catch(e)
{
console.log('error happened: ' + e.toString());
}
}
exports.execute_post = function(req, res, done){
try
{
var method = req.params.controller_method;
console.log('received post ' + method);
if (method == "register")
{
//HUB METHOD
var client = req.body;
client.ip = req.connection.remoteAddress;
server_helper.registerClient(client, function(e, response){
if (!e)
res.send(getResponse('success', 'Registration successful', response));
else
res.send(getResponse('error', e, null));
});
}
if (method == "process")
{
//PROCESSOR METHOD
var process = req.body;
var stepKey = req.query['step_key'];
client_helper.processStep(process, stepKey, function(e){
if (!e)
console.log('process step complete');
else
console.log('process step failed: ' + e);
});
res.send({status:'processing'});
}
if (method == "step_notify")
{
//HUB METHOD
console.log('step notify happened');
console.log(req.body);
var notification = req.body;
server_helper.emitStepMessage(notification.data, notification.message, function(e){
if (e)
{
res.send({status:'notify failed: ' + e});
console.log(e);
}
else
{
es.send({status:'notify OK'});
}
});
}
}
catch(e)
{
console.log('error happened: ' + e.toString());
}
}
function getResponse(status, message, data)
{
return {'status':status, 'message':message, 'data':data}
}