feat: add health endpoint
Checks DB connection & lock status.
I'm largely unfamiliar with TS (and Mongo for that matter lol), but this change has achieved my goal and seems to function well. Hopefully it's suitable. Let me know what you think.
Responses
Connected and unlocked:
{
"status": "ok",
"db_health": {
"status": "UP",
"details": {
"version": "6.0.19",
"uptime": 6843,
"writable": true
}
}
}
Connected and locked:
{
"status": "warning",
"db_health": {
"status": "READONLY",
"details": {
"version": "6.0.19",
"uptime": 7244,
"writable": false
},
"message": "Database is read-only (fsyncLock enabled)"
}
}
Disconnected:
{
"status": "error",
"db_health": {
"status": "DOWN",
"message": "Error querying database health"
}
}
On second thoughts, perhaps READONLY should be WARNING... Open to thoughts.
Hello, nice idea!
I feel like this could benefit a little authentication. Can you tell me what's possible for you in your context for authentication? Maybe http basic auth could do the work
I'm not convinced authentication should be necessary for this, but I'm by no means against it, and it wouldn't be breaking for my use case (Docker healthcheck, just runs an arbitrary command and looks at the return code to determine success/failure).
That said, it's probably not something I'd be prepared to implement personally given my current level of knowledge with both TypeScript and your_spotify...
Perhaps, as a middle-ground solution, the MongoDB version could be removed from the response? I feel this would alleviate any potential concerns with the endpoint being unauthenticated.
@Yooooomi please let me know if you're interested in going ahead with this, or have any further thoughts. I'd love to see the feature added but will close the PR if not.