HealthCheckController.js 1.0 KB

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