2019-07-03 12:41:01 +00:00
|
|
|
const request = require('request')
|
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const settings = require('settings-sharelatex')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
healthCheck(req, res) {
|
|
|
|
const opts = {
|
|
|
|
url: `http://localhost:3005/user/${settings.healthCheckUserId}/check`,
|
|
|
|
json: {
|
|
|
|
words: ['helllo'],
|
|
|
|
language: 'en'
|
|
|
|
},
|
|
|
|
timeout: 1000 * 20
|
|
|
|
}
|
|
|
|
return request.post(opts, function(err, response, body) {
|
|
|
|
if (err != null) {
|
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
2019-07-11 10:29:00 +00:00
|
|
|
|
|
|
|
const misspellings =
|
|
|
|
body && body.misspellings ? body.misspellings[0] : undefined
|
|
|
|
const numberOfSuggestions =
|
|
|
|
misspellings && misspellings.suggestions
|
|
|
|
? misspellings.suggestions.length
|
|
|
|
: 0
|
|
|
|
|
2019-07-03 12:41:01 +00:00
|
|
|
if (numberOfSuggestions > 10) {
|
|
|
|
logger.log('health check passed')
|
2019-07-11 10:29:00 +00:00
|
|
|
res.sendStatus(200)
|
2019-07-03 12:41:01 +00:00
|
|
|
} else {
|
|
|
|
logger.err({ body, numberOfSuggestions }, 'health check failed')
|
2019-07-11 10:29:00 +00:00
|
|
|
res.sendStatus(500)
|
2019-07-03 12:41:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|