diff --git a/webui/src/lib/api.ts b/webui/src/lib/api.ts index 25aba18..14ccc6b 100644 --- a/webui/src/lib/api.ts +++ b/webui/src/lib/api.ts @@ -134,4 +134,7 @@ export const instancesApi = { const params = lines ? `?lines=${lines}` : ""; return apiCall(`/instances/${name}/logs${params}`, {}, "text"); }, + + // GET /instances/{name}/proxy/health + getHealth: (name: string) => apiCall(`/instances/${name}/proxy/health`), }; diff --git a/webui/src/lib/healthService.ts b/webui/src/lib/healthService.ts index 2f52c97..025d29e 100644 --- a/webui/src/lib/healthService.ts +++ b/webui/src/lib/healthService.ts @@ -1,4 +1,5 @@ import { type HealthStatus } from '@/types/instance' +import { instancesApi } from '@/lib/api' type HealthCallback = (health: HealthStatus) => void @@ -8,31 +9,33 @@ class HealthService { async checkHealth(instanceName: string): Promise { try { - const response = await fetch(`/api/v1/instances/${instanceName}/proxy/health`) + await instancesApi.getHealth(instanceName) - if (response.status === 200) { - return { - status: 'ok', - lastChecked: new Date() + return { + status: 'ok', + lastChecked: new Date() + } + } catch (error) { + if (error instanceof Error) { + // Check if it's a 503 (service unavailable - loading) + if (error.message.includes('503')) { + return { + status: 'loading', + message: 'Instance is starting up', + lastChecked: new Date() + } } - } else if (response.status === 503) { - const data = await response.json() - return { - status: 'loading', - message: data.error.message, - lastChecked: new Date() - } - } else { + return { status: 'error', - message: `HTTP ${response.status}`, + message: error.message, lastChecked: new Date() } } - } catch (error) { + return { status: 'error', - message: 'Network error', + message: 'Unknown error', lastChecked: new Date() } } @@ -82,7 +85,7 @@ class HealthService { }, 60000) this.intervals.set(instanceName, interval) - }, 2000) + }, 5000) } private stopHealthCheck(instanceName: string): void {