feat: Consolidate version display to use health endpoint.

This commit is contained in:
Elisiário Couto
2025-09-22 18:43:53 +01:00
parent e9924e9d96
commit 76a30d23af
4 changed files with 14 additions and 32 deletions

View File

@@ -30,16 +30,7 @@ export function SiteHeader() {
refetchInterval: 30000,
});
const {
data: versionData,
isLoading: versionLoading,
isError: versionError,
} = useQuery({
queryKey: ["version"],
queryFn: apiClient.getVersion,
refetchInterval: 5 * 60 * 1000, // Refetch version every 5 minutes
retry: 1, // Only retry once since version is less critical
});
return (
<header className="flex h-16 shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear pt-safe-top">
@@ -56,13 +47,13 @@ export function SiteHeader() {
<div className="ml-auto flex items-center space-x-3">
{/* Version display */}
<div className="flex items-center space-x-1">
{versionLoading ? (
{healthLoading ? (
<span className="text-xs text-muted-foreground">v...</span>
) : versionError || !versionData ? (
) : healthError || !healthStatus ? (
<span className="text-xs text-muted-foreground">v?</span>
) : (
<span className="text-xs text-muted-foreground">
v{versionData.version}
v{healthStatus.version || "?"}
</span>
)}
</div>

View File

@@ -10,7 +10,6 @@ import type {
NotificationService,
NotificationServicesResponse,
HealthData,
VersionData,
AccountUpdate,
TransactionStats,
} from "../types/api";
@@ -168,14 +167,7 @@ export const apiClient = {
return response.data.data;
},
// Get version information
getVersion: async (): Promise<VersionData> => {
// Use the root endpoint (/) which provides version information
const response = await api.get<VersionData>("/", {
baseURL: import.meta.env.VITE_API_URL?.replace('/api/v1', '') || '',
});
return response.data;
},
// Analytics endpoints
getTransactionStats: async (days?: number): Promise<TransactionStats> => {

View File

@@ -197,6 +197,7 @@ export interface NotificationServicesResponse {
export interface HealthData {
status: string;
config_loaded?: boolean;
version?: string;
message?: string;
error?: string;
}

View File

@@ -82,15 +82,6 @@ def create_app() -> FastAPI:
app.include_router(sync.router, prefix="/api/v1", tags=["sync"])
app.include_router(notifications.router, prefix="/api/v1", tags=["notifications"])
@app.get("/")
async def root():
# Get version dynamically
try:
version = metadata.version("leggen")
except metadata.PackageNotFoundError:
version = "unknown"
return {"message": "Leggen API is running", "version": version}
@app.get("/api/v1/health")
async def health():
"""Health check endpoint for API connectivity"""
@@ -99,11 +90,18 @@ def create_app() -> FastAPI:
config_loaded = config._config is not None
# Get version dynamically
try:
version = metadata.version("leggen")
except metadata.PackageNotFoundError:
version = "dev"
return APIResponse(
success=True,
data={
"status": "healthy",
"config_loaded": config_loaded,
"version": version,
"message": "API is running and responsive",
},
message="Health check successful",