diff --git a/sales/customer/app.js b/sales/customer/app.js index 7888ca4..5905caa 100644 --- a/sales/customer/app.js +++ b/sales/customer/app.js @@ -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']; @@ -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, diff --git a/sales/customer/openapi.yaml b/sales/customer/openapi.yaml index 8f79524..5d590fd 100644 --- a/sales/customer/openapi.yaml +++ b/sales/customer/openapi.yaml @@ -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