feat(healthcheck): add /_health endpoint

This endpoint returns the internal readiness state used by
the realtime code to indicate whether HedgeDoc is performing
properly. As it only returns the state of a variable, it is
less resource hungry compared to a call to /status for
checking the health of HedgeDoc.

By prepending the route with an underscore, it should not be conflicting with already created pads in FreeURL mode.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-03-07 15:26:25 +01:00 committed by David Mehren
parent 4cf56bfdca
commit 9949e3a875
3 changed files with 12 additions and 1 deletions

View file

@ -12,6 +12,16 @@ const { urlencodedParser } = require('./utils')
const statusRouter = module.exports = Router()
statusRouter.get('/_health', function (req, res) {
res.set({
'Cache-Control': 'private', // only cache by client
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
})
res.send({
ready: !realtime.maintenance
})
})
// get status
statusRouter.get('/status', function (req, res, next) {
realtime.getStatus(function (data) {