huge refactor on web-api and web-app
This commit is contained in:
parent
1d299e52d4
commit
265e10a658
23 changed files with 1545 additions and 1233 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -11,15 +11,22 @@ export const healthRoutes = new Hono();
|
|||
|
||||
// Basic health check
|
||||
healthRoutes.get('/', c => {
|
||||
return c.json({
|
||||
logger.debug('Basic health check requested');
|
||||
|
||||
const response = {
|
||||
status: 'healthy',
|
||||
service: 'web-api',
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
};
|
||||
|
||||
logger.info('Basic health check successful', { status: response.status });
|
||||
return c.json(response);
|
||||
});
|
||||
|
||||
// Detailed health check with database connectivity
|
||||
healthRoutes.get('/detailed', async c => {
|
||||
logger.debug('Detailed health check requested');
|
||||
|
||||
const health = {
|
||||
status: 'healthy',
|
||||
service: 'web-api',
|
||||
|
|
@ -31,6 +38,7 @@ healthRoutes.get('/detailed', async c => {
|
|||
};
|
||||
|
||||
// Check MongoDB
|
||||
logger.debug('Checking MongoDB connectivity');
|
||||
try {
|
||||
const mongoClient = getMongoDBClient();
|
||||
if (mongoClient.connected) {
|
||||
|
|
@ -38,26 +46,34 @@ healthRoutes.get('/detailed', async c => {
|
|||
const db = mongoClient.getDatabase();
|
||||
await db.admin().ping();
|
||||
health.checks.mongodb = { status: 'healthy', message: 'Connected and responsive' };
|
||||
logger.debug('MongoDB health check passed');
|
||||
} else {
|
||||
health.checks.mongodb = { status: 'unhealthy', message: 'Not connected' };
|
||||
logger.warn('MongoDB health check failed - not connected');
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
health.checks.mongodb = {
|
||||
status: 'unhealthy',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: errorMessage,
|
||||
};
|
||||
logger.error('MongoDB health check failed', { error: errorMessage });
|
||||
}
|
||||
|
||||
// Check PostgreSQL
|
||||
logger.debug('Checking PostgreSQL connectivity');
|
||||
try {
|
||||
const postgresClient = getPostgreSQLClient();
|
||||
await postgresClient.query('SELECT 1');
|
||||
health.checks.postgresql = { status: 'healthy', message: 'Connected and responsive' };
|
||||
logger.debug('PostgreSQL health check passed');
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
health.checks.postgresql = {
|
||||
status: 'unhealthy',
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
message: errorMessage,
|
||||
};
|
||||
logger.error('PostgreSQL health check failed', { error: errorMessage });
|
||||
}
|
||||
|
||||
// Overall status
|
||||
|
|
@ -65,5 +81,19 @@ healthRoutes.get('/detailed', async c => {
|
|||
health.status = allHealthy ? 'healthy' : 'unhealthy';
|
||||
|
||||
const statusCode = allHealthy ? 200 : 503;
|
||||
|
||||
if (allHealthy) {
|
||||
logger.info('Detailed health check successful - all systems healthy', {
|
||||
mongodb: health.checks.mongodb.status,
|
||||
postgresql: health.checks.postgresql.status
|
||||
});
|
||||
} else {
|
||||
logger.warn('Detailed health check failed - some systems unhealthy', {
|
||||
mongodb: health.checks.mongodb.status,
|
||||
postgresql: health.checks.postgresql.status,
|
||||
overallStatus: health.status
|
||||
});
|
||||
}
|
||||
|
||||
return c.json(health, statusCode);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue