|
|
@@ -2,7 +2,7 @@
|
|
2
|
2
|
|
|
3
|
3
|
const apiSchema = require('../../schemas/api')
|
|
4
|
4
|
const errorSchema = require('../../schemas/errors')
|
|
5
|
|
-/* const healthSchema = require('../../schemas/health') // todo: maybe write healthSchema? */
|
|
|
5
|
+const healthSchema = require('../../schemas/health') // todo: maybe write healthSchema?
|
|
6
|
6
|
|
|
7
|
7
|
const pluginConfig = {
|
|
8
|
8
|
handlerType: 'health',
|
|
|
@@ -12,8 +12,10 @@ const pluginConfig = {
|
|
12
|
12
|
}
|
|
13
|
13
|
}
|
|
14
|
14
|
|
|
|
15
|
+const validators = {}
|
|
|
16
|
+
|
|
15
|
17
|
const responseSchemas = {
|
|
16
|
|
- api: apiSchema.single,
|
|
|
18
|
+ health: healthSchema.stats,
|
|
17
|
19
|
error: errorSchema.single
|
|
18
|
20
|
}
|
|
19
|
21
|
|
|
|
@@ -27,17 +29,13 @@ module.exports = {
|
|
27
|
29
|
cors: true,
|
|
28
|
30
|
handler: async function (request, h) {
|
|
29
|
31
|
const { healthService } = request.server.services()
|
|
30
|
|
-
|
|
31
|
|
- const res = {
|
|
32
|
|
- ok: true,
|
|
33
|
|
- handler: pluginConfig.handlerType,
|
|
34
|
|
- data:null
|
|
35
|
|
- }
|
|
36
|
|
-
|
|
37
|
|
- res.data = await healthService.getStats()
|
|
38
|
|
-
|
|
|
32
|
+ const stats = healthService.getStats()
|
|
39
|
33
|
try {
|
|
40
|
|
- return h.response(res).code(200)
|
|
|
34
|
+ return h.response(({
|
|
|
35
|
+ ok:true,
|
|
|
36
|
+ handler: pluginConfig.handlerType,
|
|
|
37
|
+ data: stats
|
|
|
38
|
+ })).code(200)
|
|
41
|
39
|
} catch (err) {
|
|
42
|
40
|
return h
|
|
43
|
41
|
.response({
|
|
|
@@ -49,15 +47,16 @@ module.exports = {
|
|
49
|
47
|
}
|
|
50
|
48
|
},
|
|
51
|
49
|
validate: {
|
|
|
50
|
+ ...validators,
|
|
52
|
51
|
failAction: 'log'
|
|
53
|
52
|
},
|
|
54
|
53
|
|
|
55
|
54
|
response: {
|
|
56
|
55
|
status: {
|
|
57
|
56
|
200: apiSchema.single
|
|
58
|
|
- // .append({
|
|
59
|
|
- // data: responseSchemas.api,
|
|
60
|
|
- // })
|
|
|
57
|
+ .append({
|
|
|
58
|
+ data: responseSchemas.health,
|
|
|
59
|
+ })
|
|
61
|
60
|
.label('api_single_res'),
|
|
62
|
61
|
409: apiSchema.single
|
|
63
|
62
|
.append({
|