2022-12-20 07:11:25 -05:00
|
|
|
import request from 'request'
|
|
|
|
import logger from '@overleaf/logger'
|
|
|
|
import settings from '@overleaf/settings'
|
|
|
|
import OError from '@overleaf/o-error'
|
2019-07-03 08:41:01 -04:00
|
|
|
|
2022-12-20 07:11:25 -05:00
|
|
|
export function healthCheck(req, res) {
|
|
|
|
const opts = {
|
2024-04-25 08:56:00 -04:00
|
|
|
url: `http://127.0.0.1:3005/user/${settings.healthCheckUserId}/check`,
|
2022-12-20 07:11:25 -05:00
|
|
|
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-03 08:41:01 -04:00
|
|
|
}
|
2019-07-11 06:29:00 -04:00
|
|
|
|
2022-12-20 07:11:25 -05:00
|
|
|
const misspellings =
|
|
|
|
body && body.misspellings ? body.misspellings[0] : undefined
|
|
|
|
const numberOfSuggestions =
|
|
|
|
misspellings && misspellings.suggestions
|
|
|
|
? misspellings.suggestions.length
|
|
|
|
: 0
|
2019-07-11 06:29:00 -04:00
|
|
|
|
2022-12-20 07:11:25 -05:00
|
|
|
if (numberOfSuggestions > 10) {
|
|
|
|
logger.debug('health check passed')
|
|
|
|
res.sendStatus(200)
|
|
|
|
} else {
|
|
|
|
logger.err(
|
|
|
|
new OError('health check failed', { body, numberOfSuggestions })
|
|
|
|
)
|
|
|
|
res.sendStatus(500)
|
|
|
|
}
|
|
|
|
})
|
2019-07-03 08:41:01 -04:00
|
|
|
}
|