UNPKG

nodejs-health-checker

Version:

Simple Nodejs package to simplify applications based in Node, to trace the healthy of the pods

39 lines 1.08 kB
export async function checkWebIntegration(config) { const controller = new AbortController(); let timeoutId; try { const headers = config.headers?.reduce((acc, item) => { acc[item.key] = item.value; return acc; }, {}); timeoutId = setTimeout(() => { controller.abort(); }, config.timeout); const response = await fetch(config.host, { headers, signal: controller.signal, // Force connection close keepalive: false, }); // Force close the response body if (response.body) { response.body.cancel(); } return { status: response.status === 200, error: response.status !== 200 ? { http_status: response.status } : undefined, }; } catch (error) { return { status: false, error, }; } finally { if (timeoutId) { clearTimeout(timeoutId); } } } //# sourceMappingURL=web-service.js.map