2019-07-03 12:41:01 +00:00
|
|
|
const request = require('request')
|
2021-12-14 13:00:35 +00:00
|
|
|
const logger = require('@overleaf/logger')
|
2021-07-12 16:47:20 +00:00
|
|
|
const settings = require('@overleaf/settings')
|
2020-06-03 09:14:44 +00:00
|
|
|
const OError = require('@overleaf/o-error')
|
2019-07-03 12:41:01 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
healthCheck(req, res) {
|
|
|
|
const opts = {
|
|
|
|
url: `http://localhost:3005/user/${settings.healthCheckUserId}/check`,
|
|
|
|
json: {
|
|
|
|
words: ['helllo'],
|
2021-07-13 11:04:47 +00:00
|
|
|
language: 'en',
|
2019-07-03 12:41:01 +00:00
|
|
|
},
|
2021-07-13 11:04:47 +00:00
|
|
|
timeout: 1000 * 20,
|
2019-07-03 12:41:01 +00:00
|
|
|
}
|
2020-08-10 16:23:15 +00:00
|
|
|
return request.post(opts, function (err, response, body) {
|
2019-07-03 12:41:01 +00:00
|
|
|
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 {
|
2020-06-03 09:14:44 +00:00
|
|
|
logger.err(
|
|
|
|
new OError('health check failed', { body, numberOfSuggestions })
|
|
|
|
)
|
2019-07-11 10:29:00 +00:00
|
|
|
res.sendStatus(500)
|
2019-07-03 12:41:01 +00:00
|
|
|
}
|
|
|
|
})
|
2021-07-13 11:04:47 +00:00
|
|
|
},
|
2019-07-03 12:41:01 +00:00
|
|
|
}
|