Skip to content

Commit

Permalink
add is alive and is healthy endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
chrypnotoad committed Aug 1, 2024
1 parent c3c462a commit de7827e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ GET `/cleanStatTable` this endpoint trigger purging of table that store interfac

GET `/cleanTxTable` this endpoint trigger purging of table that store transaction logging

# Health Check

GET `/is-alive` this endpoint returns 200 if the server is running.
GET `/is-healthy` currently the same as `/is-alive` but will be expanded.

# Contributing

Contributions are very welcome! Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our [code of conduct](CODE_OF_CONDUCT.md) so we can all enjoy the effort we put into this project.
15 changes: 15 additions & 0 deletions src/routes/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express, { Request, Response, Router } from 'express'
import { nestedCountersInstance } from '../utils/nestedCounters'

export const healthCheckRouter: Router = express.Router()

healthCheckRouter.get('/is-alive', (req: Request, res: Response) => {
nestedCountersInstance.countEvent('api', 'is-alive')
return res.status(200);
})

healthCheckRouter.get('/is-healthy', (req: Request, res: Response) => {
// TODO: Add actual health check logic
nestedCountersInstance.countEvent('api', 'health-check')
return res.status(200);
})
7 changes: 2 additions & 5 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from './utils'
import { router as logRoute } from './routes/log'
import { router as authenticate } from './routes/authenticate'
import { healthCheckRouter } from './routes/healthCheck'
import { Request, Response } from 'express'
import { CONFIG, CONFIG as config } from './config'
import blackList from '../blacklist.json'
Expand Down Expand Up @@ -116,11 +117,6 @@ app.get('/api/subscribe', authorize, (req: Request, res: Response) => {
res.end(`Successfully changed to ${ip}:${port}`)
})

app.get('/api/health', (req: Request, res: Response) => {
nestedCountersInstance.countEvent('api', 'health')
return res.json({ healthy: true }).status(200)
})

app.get('/counts', authorize, (req: Request, res: Response) => {
nestedCountersInstance.countEvent('api', 'counts')
const arrayReport = nestedCountersInstance.arrayitizeAndSort(nestedCountersInstance.eventCounters)
Expand Down Expand Up @@ -194,6 +190,7 @@ app.use(async (req: Request, res: Response, next: NextFunction) => {

app.use('/log', authorize, logRoute)
app.use('/authenticate', authenticate)
app.use('/', healthCheckRouter)
app.use(injectIP)
// reject subscription methods from http
app.use(rejectSubscription)
Expand Down

0 comments on commit de7827e

Please sign in to comment.