Skip to content

Commit

Permalink
Adds /health route to customer information service (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
rspurgeon authored Aug 24, 2023
1 parent aff5f99 commit e2daec9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
19 changes: 17 additions & 2 deletions sales/customer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ app.use(
}),
);

// Health check endpoint
app.get('/health', (req, res) => {
res.status(200).json({ status: 'OK' });
});

app.use((req, res, next) => {

if (req.path === '/health') {
return next();
}

// Extract username from X-Consumer-Username header
const usernameHeader = req.headers['x-consumer-username'];

Expand Down Expand Up @@ -56,8 +66,13 @@ app.get('/customer', (req, res) => {
});

// Error handler
app.use((err, _, res) => {
// format error
app.use((err, req, res, next) => {
// If it's the health check path, provide a clear response
if (req.path === '/health') {
return res.status(503).json({ status: 'unhealthy' });
}

// format error for other paths
res.status(err.status || 500).json({
message: err.message,
errors: err.errors,
Expand Down
25 changes: 25 additions & 0 deletions sales/customer/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ servers:
description: KongAir API Server

paths:
/health:
get:
summary: Health check endpoint for Kubernetes
description: Endpoint that returns the service health status.
responses:
'200':
description: Service is healthy
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: "OK"
'500':
description: Service is unhealthy
content:
application/json:
schema:
type: object
properties:
status:
type: string
example: "unhealthy"
"/customer":
get:
summary: Fetch a customers information
Expand Down

0 comments on commit e2daec9

Please sign in to comment.