Refactor response handling and health check endpoints
- Enhance response model with additional fields and validation - Update health and server router implementations - Improve frontend type definitions and API integration - Clean up documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { get } from "./client";
|
||||
import { ENDPOINTS } from "./endpoints";
|
||||
import type { HealthResponse } from "../types/server";
|
||||
import type { HealthResponse } from "../types/response";
|
||||
|
||||
export async function fetchHealth(): Promise<HealthResponse> {
|
||||
return get<HealthResponse>(ENDPOINTS.health);
|
||||
|
||||
@@ -36,3 +36,23 @@ export interface ErrorResponse {
|
||||
/** Unique ID for correlating this error with request logs on both frontend and backend. */
|
||||
correlation_id?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardized health check response.
|
||||
* Mirrors `backend/app/models/response.py:HealthResponse`.
|
||||
*/
|
||||
export interface HealthResponse {
|
||||
/** Application health status: 'ok' when healthy, 'unavailable' otherwise. */
|
||||
status: "ok" | "unavailable";
|
||||
/** fail2ban daemon status: 'online' when reachable, 'offline' otherwise. */
|
||||
fail2ban: "online" | "offline";
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardized flush-logs command response.
|
||||
* Mirrors `backend/app/models/response.py:FlushLogsResponse`.
|
||||
*/
|
||||
export interface FlushLogsResponse {
|
||||
/** Human-readable result message from fail2ban. */
|
||||
message: string;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
* `backend/app/models/server.py`
|
||||
*/
|
||||
|
||||
import type { HealthResponse as HealthResponseBase } from "./response";
|
||||
|
||||
/** Cached fail2ban server health snapshot. */
|
||||
export interface ServerStatus {
|
||||
/** Whether fail2ban is reachable via its socket. */
|
||||
@@ -23,8 +25,8 @@ export interface ServerStatusResponse {
|
||||
status: ServerStatus;
|
||||
}
|
||||
|
||||
/** Response shape for ``GET /api/health``. */
|
||||
export interface HealthResponse {
|
||||
status: "ok";
|
||||
fail2ban: "online" | "offline";
|
||||
}
|
||||
/**
|
||||
* Response shape for ``GET /api/health``.
|
||||
* Re-exports the canonical type from `types/response.ts`.
|
||||
*/
|
||||
export type HealthResponse = HealthResponseBase;
|
||||
|
||||
Reference in New Issue
Block a user