Skip to content

Commit

Permalink
Introduced two new endpoints, /is-alive and /is-healthy, for heal…
Browse files Browse the repository at this point in the history
…th checks. Documentation updated accordingly.
  • Loading branch information
asyed94 authored and urnotsam committed Aug 26, 2024
1 parent 65a7520 commit f7f0ed2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This is a node that runs as part of the shardus network, with the function of re

To release, just run `npm run release`

## 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.
14 changes: 14 additions & 0 deletions src/routes/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FastifyPluginCallback } from 'fastify'

export const healthCheckRouter: FastifyPluginCallback = function (fastify, opts, done) {
fastify.get('/is-alive', (req, res) => {
return res.status(200).send('OK')
})

fastify.get('/is-healthy', (req, res) => {
// TODO: Add actual health check logic
return res.status(200).send('OK')
})

done()
}
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { loadGlobalAccounts, syncGlobalAccount } from './GlobalAccount'
import { setShutdownCycleRecord, cycleRecordWithShutDownMode } from './Data/Cycles'
import { registerRoutes } from './API'
import { Utils as StringUtils } from '@shardus/types'
import { healthCheckRouter } from './routes/healthCheck'

const configFile = join(process.cwd(), 'archiver-config.json')
let logDir: string
Expand Down Expand Up @@ -438,6 +439,7 @@ async function startServer(): Promise<void> {
timeWindow: 10,
allowList: ['127.0.0.1', '0.0.0.0'], // Excludes local IPs from rate limits
})
await server.register(healthCheckRouter)

server.addContentTypeParser('application/json', { parseAs: 'string' }, (req, body, done) => {
try {
Expand Down

0 comments on commit f7f0ed2

Please sign in to comment.