HealthCheckController.js 981 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import request from 'request'
  2. import logger from '@overleaf/logger'
  3. import settings from '@overleaf/settings'
  4. import OError from '@overleaf/o-error'
  5. export function healthCheck(req, res) {
  6. const opts = {
  7. url: `http://localhost:3005/user/${settings.healthCheckUserId}/check`,
  8. json: {
  9. words: ['helllo'],
  10. language: 'en',
  11. },
  12. timeout: 1000 * 20,
  13. }
  14. return request.post(opts, function (err, response, body) {
  15. if (err != null) {
  16. return res.sendStatus(500)
  17. }
  18. const misspellings =
  19. body && body.misspellings ? body.misspellings[0] : undefined
  20. const numberOfSuggestions =
  21. misspellings && misspellings.suggestions
  22. ? misspellings.suggestions.length
  23. : 0
  24. if (numberOfSuggestions > 10) {
  25. logger.debug('health check passed')
  26. res.sendStatus(200)
  27. } else {
  28. logger.err(
  29. new OError('health check failed', { body, numberOfSuggestions })
  30. )
  31. res.sendStatus(500)
  32. }
  33. })
  34. }