diff --git a/api/server.mjs b/api/server.mjs index 0e92880..5001026 100644 --- a/api/server.mjs +++ b/api/server.mjs @@ -41,6 +41,8 @@ export default class Server { ip: ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress, }) }) + + let healthChecks = 0 this.flaska.after(function(ctx) { let ended = performance.now() - ctx.__started @@ -54,6 +56,18 @@ export default class Server { if (ctx.status >= 500) { 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), diff --git a/api/test/routes.mjs b/api/test/routes.mjs index eb48507..843a3c5 100644 --- a/api/test/routes.mjs +++ b/api/test/routes.mjs @@ -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'),