Initial commit
This commit is contained in:
commit
92e96b9107
85 changed files with 24969 additions and 0 deletions
32
app/server/api/health.get.ts
Normal file
32
app/server/api/health.get.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import mongoose from 'mongoose'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const checks = {
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
uptime: process.uptime(),
|
||||
mongodb: 'disconnected',
|
||||
memory: process.memoryUsage(),
|
||||
}
|
||||
|
||||
// Check MongoDB connection
|
||||
try {
|
||||
if (mongoose.connection.readyState === 1) {
|
||||
checks.mongodb = 'connected'
|
||||
} else {
|
||||
checks.mongodb = 'disconnected'
|
||||
}
|
||||
} catch (error) {
|
||||
checks.mongodb = 'error'
|
||||
}
|
||||
|
||||
// Return 503 if any critical service is down
|
||||
const isHealthy = checks.mongodb === 'connected'
|
||||
|
||||
if (!isHealthy) {
|
||||
setResponseStatus(event, 503)
|
||||
checks.status = 'unhealthy'
|
||||
}
|
||||
|
||||
return checks
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue