Skip to content

Commit

Permalink
feat(routes) add helth check route
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoPorfirio01 committed Jan 3, 2025
1 parent 9b74a97 commit ce795e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apps/api/src/http/routes/health-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FastifyInstance } from 'fastify'
import { z } from 'zod'

export async function healthCheck(app: FastifyInstance) {
app.get(
'/health',
{
schema: {
response: {
200: z.object({
status: z.string(),
timestamp: z.string(),
}),
},
},
},
async () => {
return {
status: 'ok',
timestamp: new Date().toISOString(),
}
},
)
}
4 changes: 4 additions & 0 deletions apps/api/src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { getChatGroups } from './routes/chat/get-chat-groups'
import { getChatGroupsUser } from './routes/chat/get-chat-groups-user'
import { getChats } from './routes/chat/get-chats'
import { updateChatGroup } from './routes/chat/update-chat-group'
import { healthCheck } from './routes/health-check'

// Extend the FastifyInstance type to include the 'io' property
interface CustomFastifyInstance extends FastifyInstance {
Expand Down Expand Up @@ -117,6 +118,9 @@ app.setErrorHandler(errorHandler)

// ### Routes ###

// Add this before other routes
app.register(healthCheck)

// -> Auth
app.register(fastifyJwt, {
secret: env.JWT_SECRET,
Expand Down

0 comments on commit ce795e6

Please sign in to comment.