forked from CompassPHS/shuttle.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
82 lines (66 loc) · 1.98 KB
/
routes.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
var jobManager = require('./jobManager')
_ = require('lodash')
;
var routes = [];
routes.push({
path:'/{job}',
method:'GET',
handler:function(request,reply) {
var job = jobManager.registry[request.params.job];
reply({
id:request.params.job,
name:job.name,
children:job.children.map(function(child){return child.pid;})
})
}
})
routes.push({
path:'/{job}/{id}',
method:'get',
handler:function(request,reply){
var job = jobManager.registry[request.params.job];
var child = _.find(job.children, {'pid':parseInt(request.params.id)});
reply({
id:child.pid,
started:child.started
})
}
})
Object.keys(jobManager.registry)
.forEach(function(registrationName){
var registration = jobManager.registry[registrationName];
if(registration.job.routes){
registration.job.routes.forEach(function(route){
routes.push({
path:'/' + registrationName + route.path,
method:route.method,
handler:function(request, reply){
var req = {
params:request.params,
body:request.payload,
query:request.query
}
route.handler(req, function(err, result, status){
if(err)
return reply(err).code(status || 500);
reply(result).code(status || 200);
})
}
})
})
}
})
/*
routes.push({
path:'/{job}',
method:'post',
handler:function(request,reply){
jobManager.registry[request.params.job]
.routes
.create(request.payload, function(err, result){
reply(err)
})
}
})
*/
module.exports = routes;