Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

get.js 1.8KB

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