Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 69x 132x 132x 132x 128x 130x 3x 3x 3x 2x 2x 1x | import { create } from 'zustand'
import { apiClient } from '@/lib/axios'
interface HealthState {
status: 'healthy' | 'degraded' | 'unhealthy'
responseTime: number | null
lastChecked: number | null
apiVersion: string | null
fetchHealth: () => Promise<void>
}
export const useHealthStore = create<HealthState>()((set) => ({
status: 'healthy',
responseTime: null,
lastChecked: null,
apiVersion: null,
fetchHealth: async () => {
const start = performance.now()
try {
const { data } = await apiClient.get('/health')
const elapsed = Math.round(performance.now() - start)
set({
status: data.status,
responseTime: elapsed,
lastChecked: Date.now(),
apiVersion: data.version ?? null,
})
} catch {
set({
status: 'unhealthy',
responseTime: null,
lastChecked: Date.now(),
apiVersion: null,
})
}
},
}))
|