| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 'use strict'
-
- const apiSchema = require('../../schemas/api')
- const errorSchema = require('../../schemas/errors')
- const healthSchema = require('../../schemas/health')
-
- const pluginConfig = {
- handlerType: 'health',
- docs: {
- description: 'Get server stats',
- notes: 'Returns stats on server status'
- }
- }
-
- const validators = {}
-
- const responseSchemas = {
- health: healthSchema.stats,
- error: errorSchema.single
- }
-
- module.exports = {
- method: 'GET',
- path: '/',
- options:{
- ...pluginConfig.docs,
- tags: ['api'],
- auth: false,
- cors: true,
- handler: async function (request, h) {
- const { healthService } = request.server.services()
- const stats = await healthService.getStats()
- try {
- return h.response(({
- ok:true,
- handler: pluginConfig.handlerType,
- data: stats
- })).code(200)
- } catch (err) {
- return h
- .response({
- ok: false,
- handler: pluginConfig.handlerType,
- data: {error: `${err}`}
- })
- .code(409)
- }
- },
- validate: {
- ...validators,
- failAction: 'log'
- },
-
- response: {
- status: {
- 200: apiSchema.single
- .append({
- data: responseSchemas.health,
- })
- .label('api_single_res'),
- 409: apiSchema.single
- .append({
- data: responseSchemas.error,
- })
- .label('error_single_res'),
- },
- },
- },
- }
|