mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 16:51:18 +00:00
a540754f6e
[misc] bulk replace localhost with 127.0.0.1 GitOrigin-RevId: d238f3635302e8ff5500d611108c4d1bef216726
37 lines
981 B
JavaScript
37 lines
981 B
JavaScript
import request from 'request'
|
|
import logger from '@overleaf/logger'
|
|
import settings from '@overleaf/settings'
|
|
import OError from '@overleaf/o-error'
|
|
|
|
export function healthCheck(req, res) {
|
|
const opts = {
|
|
url: `http://127.0.0.1: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)
|
|
}
|
|
})
|
|
}
|