server: Add specific health check route that doesn't spam logs
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

This commit is contained in:
Jonatan Nilsson 2022-08-15 08:39:59 +00:00
parent feb42c1ba7
commit 7755847af3
2 changed files with 23 additions and 0 deletions

View file

@ -42,6 +42,8 @@ export default class Server {
})
})
let healthChecks = 0
this.flaska.after(function(ctx) {
let ended = performance.now() - ctx.__started
@ -55,6 +57,18 @@ export default class Server {
level = 'error'
}
if (ctx.url === '/health') {
healthChecks++
if (healthChecks > 60 * 60 * 12) {
ctx.log[level]({
duration: Math.round(ended),
status: ctx.status,
}, `<-- ${status}${ctx.method} ${ctx.url} {has happened ${healthChecks} times}`)
healthChecks = 0
}
return
}
ctx.log[level]({
duration: Math.round(ended),
status: ctx.status,

View file

@ -7,9 +7,18 @@ export default class TestRoutes {
register(server) {
server.flaska.get('/', this.static.bind(this))
server.flaska.get('/health', this.health.bind(this))
server.flaska.get('/error', this.error.bind(this))
}
health(ctx) {
ctx.body = {
name: config.get('name'),
version: config.get('version'),
environment: config.get('NODE_ENV'),
}
}
static(ctx) {
ctx.body = {
name: config.get('name'),