Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict'
  2. const apiSchema = require('../../schemas/api')
  3. const errorSchema = require('../../schemas/errors')
  4. const healthSchema = require('../../schemas/health')
  5. const pluginConfig = {
  6. handlerType: 'health',
  7. docs: {
  8. description: 'Get server stats',
  9. notes: 'Returns stats on server status',
  10. },
  11. opts: {
  12. tags: ['api'],
  13. auth:
  14. process.env.USE_AUTH != 'true'
  15. ? false
  16. : { strategy: 'default_jwt' },
  17. cors: true,
  18. },
  19. }
  20. const validators = {}
  21. const responseSchemas = {
  22. health: healthSchema.stats,
  23. error: errorSchema.single,
  24. }
  25. module.exports = {
  26. method: 'GET',
  27. path: '/',
  28. options: {
  29. ...pluginConfig.docs,
  30. ...pluginConfig.opts,
  31. handler: async function (request, h) {
  32. const { healthService } = request.server.services()
  33. const stats = await healthService.getStats()
  34. try {
  35. return h
  36. .response({
  37. ok: true,
  38. handler: pluginConfig.handlerType,
  39. data: stats,
  40. })
  41. .code(200)
  42. } catch (err) {
  43. return h
  44. .response({
  45. ok: false,
  46. handler: pluginConfig.handlerType,
  47. data: { error: `${err}` },
  48. })
  49. .code(409)
  50. }
  51. },
  52. validate: {
  53. ...validators,
  54. failAction: 'log',
  55. },
  56. response: {
  57. status: {
  58. 200: apiSchema.single
  59. .append({
  60. data: responseSchemas.health,
  61. })
  62. .label('api_single_res'),
  63. 409: apiSchema.single
  64. .append({
  65. data: responseSchemas.error,
  66. })
  67. .label('error_single_res'),
  68. },
  69. },
  70. },
  71. }