UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g

31 lines (24 loc) 709 B
import { getProxyAgent } from '@redocly/openapi-core'; export const DEFAULT_FETCH_TIMEOUT = 3000; export type FetchWithTimeoutOptions = RequestInit & { timeout?: number; }; export default async (url: string, { timeout, ...options }: FetchWithTimeoutOptions = {}) => { if (!timeout) { return fetch(url, { ...options, dispatcher: getProxyAgent(), } as RequestInit); } const controller = new globalThis.AbortController(); const timeoutId = setTimeout(() => { controller.abort(); }, timeout); const res = await fetch(url, { signal: controller.signal, ...options, dispatcher: getProxyAgent(), } as RequestInit); clearTimeout(timeoutId); return res; };