- Заполнены заглушки: user-friendly-messages, health, aria, keyboard - backend: core/auth.py, /api/v1/stats; cached-api → backend-client при USE_MOCK_DATA=false - .env.example, middleware auth (skip при USE_MOCK_DATA), убраны неиспользуемые deps - Страницы: airworthiness, maintenance, defects, modifications; AircraftAddModal, Sidebar - Главная страница: REFLY — Контроль лётной годности (вместо Numerology App) - Линт/скрипты: eslintrc, security, cleanup, logs, api inbox/knowledge Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
/** Проверка состояния системы. MVP: проверяет бэкенд через /api/v1/health */
|
|
interface HealthCheck {
|
|
status: 'ok' | 'error';
|
|
message?: string;
|
|
}
|
|
|
|
interface HealthResult {
|
|
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
checks: {
|
|
database: HealthCheck;
|
|
backend?: HealthCheck;
|
|
};
|
|
}
|
|
|
|
export async function checkHealth(): Promise<HealthResult> {
|
|
const apiBase = process.env.NEXT_PUBLIC_API_URL || '';
|
|
const backendUrl = apiBase ? `${apiBase.replace(/\/+$/, '')}/health` : '/api/v1/health';
|
|
|
|
let backendStatus: HealthCheck = { status: 'ok' };
|
|
try {
|
|
const res = await fetch(backendUrl, { signal: AbortSignal.timeout(3000) });
|
|
if (!res.ok) backendStatus = { status: 'error', message: `HTTP ${res.status}` };
|
|
} catch (e) {
|
|
backendStatus = { status: 'error', message: e instanceof Error ? e.message : 'Backend unreachable' };
|
|
}
|
|
|
|
const dbOk = backendStatus.status === 'ok';
|
|
return {
|
|
status: dbOk ? 'healthy' : 'degraded',
|
|
checks: {
|
|
database: dbOk ? { status: 'ok' } : { status: 'error', message: 'Backend/DB check failed' },
|
|
backend: backendStatus,
|
|
},
|
|
};
|
|
}
|