2015-03-01 07:45:23 -05:00
|
|
|
request = require("request")
|
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
settings = require 'settings-sharelatex'
|
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
healthCheck: (req, res)->
|
|
|
|
opts =
|
2015-03-01 07:53:10 -05:00
|
|
|
url: "http://localhost:3005/user/#{settings.healthCheckUserId}/check"
|
2015-03-01 07:45:23 -05:00
|
|
|
json:
|
|
|
|
words:["helllo"]
|
|
|
|
language: "en"
|
2015-03-01 07:56:31 -05:00
|
|
|
timeout: 1000 * 20
|
2015-03-01 07:45:23 -05:00
|
|
|
request.post opts, (err, response, body)->
|
2016-03-01 08:20:20 -05:00
|
|
|
if err?
|
|
|
|
return res.sendStatus 500
|
2016-02-29 07:50:37 -05:00
|
|
|
numberOfSuggestions = body?.misspellings?[0]?.suggestions?.length
|
2015-03-01 07:45:23 -05:00
|
|
|
if numberOfSuggestions > 10
|
|
|
|
logger.log "health check passed"
|
2015-03-03 09:45:32 -05:00
|
|
|
res.sendStatus 200
|
2015-03-01 07:45:23 -05:00
|
|
|
else
|
|
|
|
logger.err body:body, numberOfSuggestions:numberOfSuggestions, "health check failed"
|
2015-03-03 09:45:32 -05:00
|
|
|
res.sendStatus 500
|