'use strict' const apiSchema = require('../../schemas/api') const errorSchema = require('../../schemas/errors') /* const healthSchema = require('../../schemas/health') // todo: maybe write healthSchema? */ const pluginConfig = { handlerType: 'health', docs: { description: 'Get server stats', notes: 'Returns stats on server status' } } const responseSchemas = { api: apiSchema.single, 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 res = { ok: true, handler: pluginConfig.handlerType, data:null } res.data = await healthService.getStats() try { return h.response(res).code(200) } catch (err) { return h .response({ ok: false, handler: pluginConfig.handlerType, data: {error: `${err}`} }) .code(409) } }, validate: { failAction: 'log' }, response: { status: { 200: apiSchema.single // .append({ // data: responseSchemas.api, // }) .label('api_single_res'), 409: apiSchema.single .append({ data: responseSchemas.error, }) .label('error_single_res'), }, }, }, }