TypeScript 97.5%
SQL 1.4%
Python 0.8%
1import type { ConcreteNetwork } from "@fetcha/core";2import type { ProviderHealth, ProxyProvider } from "./types";34/** Shared health probe: fetch the provider's own IP-echo endpoint through the network. */5export async function probeHealth(provider: ProxyProvider, network: ConcreteNetwork, probeUrl: string): Promise<ProviderHealth> {6 const t0 = performance.now();7 try {8 const res = await provider.fetch({9 requestId: "probe",10 attemptId: "probe",11 url: probeUrl,12 method: "GET",13 headers: { accept: "application/json" },14 timeoutMs: 15_000,15 network,16 geo: { country: null, region: null, city: null },17 followRedirects: true,18 maxRedirects: 3,19 maxResponseBytes: 65_536,20 });21 const latencyMs = Math.round(performance.now() - t0);22 if (res.status >= 200 && res.status < 400) {23 return { provider: provider.id, network, status: latencyMs > 6000 ? "degraded" : "healthy", latencyMs, checkedAt: new Date() };24 }25 return { provider: provider.id, network, status: "degraded", latencyMs, checkedAt: new Date(), detail: `probe http ${res.status}` };26 } catch (e) {27 return { provider: provider.id, network, status: "down", latencyMs: null, checkedAt: new Date(), detail: (e as Error).message };28 }29}30