Enhance API routing and health check functionality

- Added ApiRouteTemplate as a base class for defining API routes
- Implemented HealthCheckApi for health check endpoint management
- Introduced IApiRoute interface for consistent route handling
- Updated UserApiRoute to align with new routing structure
- Added HealthCheck class for health status retrieval
- Improved dependency management with new types and interfaces
This commit is contained in:
2025-11-10 22:12:41 -05:00
parent f6d0afb98a
commit ce85dd1ead
22 changed files with 183 additions and 63 deletions

43
src/api/HealthCheckApi.ts Normal file
View File

@@ -0,0 +1,43 @@
import type {HealthCheck} from '../health/HealthCheck.js';
import type {RoutePath, RouteHandler} from '../net/http/HttpRouteManger.js';
import type {IApiRoute} from './IApiRoute';
import type express from 'express';
export class HealthCheckApi implements IApiRoute {
private readonly _getRoutes: Record<string, RouteHandler>;
private readonly _postRoutes: Record<string, RouteHandler> = {};
private readonly _putRoutes: Record<string, RouteHandler> = {};
private readonly _deleteRoutes: Record<string, RouteHandler> = {};
private readonly _healthCheck: HealthCheck;
constructor(healthCheck: HealthCheck) {
this._healthCheck = healthCheck;
this._getRoutes = this.setupGETRoutes();
}
public getGETRoutes(): Record<RoutePath, RouteHandler> {
return this._getRoutes;
}
public getPOSTRoutes(): Record<RoutePath, RouteHandler> {
return this._postRoutes;
}
public getPUTRoutes(): Record<RoutePath, RouteHandler> {
return this._putRoutes;
}
public getDELETERoutes(): Record<RoutePath, RouteHandler> {
return this._deleteRoutes;
}
private setupGETRoutes(): Record<RoutePath, RouteHandler> {
return {
'/_health': (req: express.Request, res: express.Response) => {
const health = this._healthCheck.getHealth();
res.send(health);
}
};
}
}