|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+'use strict'
|
|
|
2
|
+
|
|
|
3
|
+const apiSchema = require('../../schemas/api')
|
|
|
4
|
+const errorSchema = require('../../schemas/errors')
|
|
|
5
|
+/* const healthSchema = require('../../schemas/health') // todo: maybe write healthSchema? */
|
|
|
6
|
+
|
|
|
7
|
+const pluginConfig = {
|
|
|
8
|
+ handlerType: 'health',
|
|
|
9
|
+ docs: {
|
|
|
10
|
+ description: 'Get server stats',
|
|
|
11
|
+ notes: 'Returns stats on server status'
|
|
|
12
|
+ }
|
|
|
13
|
+}
|
|
|
14
|
+
|
|
|
15
|
+const responseSchemas = {
|
|
|
16
|
+ api: apiSchema.single,
|
|
|
17
|
+ error: errorSchema.single
|
|
|
18
|
+}
|
|
|
19
|
+
|
|
|
20
|
+module.exports = {
|
|
|
21
|
+ method: 'GET',
|
|
|
22
|
+ path: '/',
|
|
|
23
|
+ options:{
|
|
|
24
|
+ ...pluginConfig.docs,
|
|
|
25
|
+ tags: ['api'],
|
|
|
26
|
+ auth: false,
|
|
|
27
|
+ cors: true,
|
|
|
28
|
+ handler: async function (request, h) {
|
|
|
29
|
+ 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
|
+
|
|
|
39
|
+ try {
|
|
|
40
|
+ return h.response(res).code(200)
|
|
|
41
|
+ } catch (err) {
|
|
|
42
|
+ return h
|
|
|
43
|
+ .response({
|
|
|
44
|
+ ok: false,
|
|
|
45
|
+ handler: pluginConfig.handlerType,
|
|
|
46
|
+ data: {error: `${err}`}
|
|
|
47
|
+ })
|
|
|
48
|
+ .code(409)
|
|
|
49
|
+ }
|
|
|
50
|
+ },
|
|
|
51
|
+ validate: {
|
|
|
52
|
+ failAction: 'log'
|
|
|
53
|
+ },
|
|
|
54
|
+
|
|
|
55
|
+ response: {
|
|
|
56
|
+ status: {
|
|
|
57
|
+ 200: apiSchema.single
|
|
|
58
|
+ // .append({
|
|
|
59
|
+ // data: responseSchemas.api,
|
|
|
60
|
+ // })
|
|
|
61
|
+ .label('api_single_res'),
|
|
|
62
|
+ 409: apiSchema.single
|
|
|
63
|
+ .append({
|
|
|
64
|
+ data: responseSchemas.error,
|
|
|
65
|
+ })
|
|
|
66
|
+ .label('error_single_res'),
|
|
|
67
|
+ },
|
|
|
68
|
+ },
|
|
|
69
|
+ },
|
|
|
70
|
+}
|