mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 21:24:50 -05:00
e0d91eaa26
Downgrade all INFO logs to DEBUG GitOrigin-RevId: 05ed582ef0721fcada059f0ad158565f50feca27
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
const request = require('request')
|
|
const logger = require('@overleaf/logger')
|
|
const settings = require('@overleaf/settings')
|
|
const OError = require('@overleaf/o-error')
|
|
|
|
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)
|
|
}
|
|
|
|
const misspellings =
|
|
body && body.misspellings ? body.misspellings[0] : undefined
|
|
const numberOfSuggestions =
|
|
misspellings && misspellings.suggestions
|
|
? misspellings.suggestions.length
|
|
: 0
|
|
|
|
if (numberOfSuggestions > 10) {
|
|
logger.debug('health check passed')
|
|
res.sendStatus(200)
|
|
} else {
|
|
logger.err(
|
|
new OError('health check failed', { body, numberOfSuggestions })
|
|
)
|
|
res.sendStatus(500)
|
|
}
|
|
})
|
|
},
|
|
}
|