Skip to content

Commit e774a38

Browse files
author
Lasim
committed
feat: Add health check endpoint for API status monitoring
1 parent e0459d6 commit e774a38

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

services/backend/api-spec.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@
9191
}
9292
}
9393
},
94+
"/api/health": {
95+
"get": {
96+
"summary": "Simple API health check",
97+
"tags": [
98+
"Health Check"
99+
],
100+
"description": "Returns basic API health status for monitoring, load balancers, and uptime checks",
101+
"responses": {
102+
"200": {
103+
"description": "Simple health check response",
104+
"content": {
105+
"application/json": {
106+
"schema": {
107+
"type": "object",
108+
"properties": {
109+
"status": {
110+
"type": "string",
111+
"enum": [
112+
"ok"
113+
],
114+
"description": "Health status indicator"
115+
}
116+
},
117+
"required": [
118+
"status"
119+
],
120+
"additionalProperties": false,
121+
"description": "Simple health check response"
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}
128+
},
94129
"/api/db/status": {
95130
"get": {
96131
"summary": "Get database status",

services/backend/api-spec.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ paths:
6262
- version
6363
additionalProperties: false
6464
description: API health check information
65+
/api/health:
66+
get:
67+
summary: Simple API health check
68+
tags:
69+
- Health Check
70+
description: Returns basic API health status for monitoring, load balancers, and
71+
uptime checks
72+
responses:
73+
"200":
74+
description: Simple health check response
75+
content:
76+
application/json:
77+
schema:
78+
type: object
79+
properties:
80+
status:
81+
type: string
82+
enum:
83+
- ok
84+
description: Health status indicator
85+
required:
86+
- status
87+
additionalProperties: false
88+
description: Simple health check response
6589
/api/db/status:
6690
get:
6791
summary: Get database status
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { type FastifyInstance } from 'fastify'
2+
import { z } from 'zod'
3+
import { zodToJsonSchema } from 'zod-to-json-schema'
4+
5+
// Response schema for the simple health check endpoint
6+
const healthResponseSchema = z.object({
7+
status: z.literal('ok').describe('Health status indicator')
8+
});
9+
10+
export default async function healthRoute(server: FastifyInstance) {
11+
// Simple health check endpoint for monitoring/load balancers
12+
server.get('/health', {
13+
schema: {
14+
tags: ['Health Check'],
15+
summary: 'Simple API health check',
16+
description: 'Returns basic API health status for monitoring, load balancers, and uptime checks',
17+
response: {
18+
200: zodToJsonSchema(healthResponseSchema.describe('Simple health check response'), {
19+
$refStrategy: 'none',
20+
target: 'openApi3'
21+
})
22+
}
23+
}
24+
}, async () => {
25+
return { status: 'ok' }
26+
});
27+
}

services/backend/src/routes/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import globalSettingsRoute from './globalSettings'
1313
import teamsRoute from './teams'
1414
// Import cloud credentials routes
1515
import cloudCredentialsRoute from './cloud-credentials'
16+
// Import health check route
17+
import healthRoute from './health'
1618

1719
// Response schema for the root health check endpoint
1820
const healthCheckResponseSchema = z.object({
@@ -25,6 +27,9 @@ const healthCheckResponseSchema = z.object({
2527
export const registerRoutes = (server: FastifyInstance): void => {
2628
// Register all API routes with centralized /api prefix
2729
server.register(async (apiInstance) => {
30+
// Register health check route
31+
await apiInstance.register(healthRoute);
32+
2833
// Register the individual database setup routes
2934
await apiInstance.register(dbStatusRoute);
3035
await apiInstance.register(dbSetupRoute);

0 commit comments

Comments
 (0)