Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import { safeFetchWrap } from '@atproto-labs/fetch-node';
export const USER_AGENT = 'atmofed (+https://tangled.org/robin.berjon.com/atmofed)';
// Every URL this library fetches comes from somewhere untrusted: a DID// document, an actor document, a profile field, a form. The atproto labs// wrapper refuses private and non-unicast addresses (also across redirects,// since it checks at dispatch time), caps response size, and times out.//// `dev` loosens all of that so the demo can run against 127.0.0.1 over plain// http. Never set it in production.export function createFetch({ fetch: baseFetch = globalThis.fetch, dev = false, timeout = 10_000, responseMaxSize = 1024 * 1024,} = {}) { const safe = safeFetchWrap({ fetch: baseFetch, timeout, responseMaxSize, allowHttp: dev, allowPrivateIps: dev, allowIpHost: dev, allowCustomPort: dev, allowImplicitRedirect: true, }); // Callers (the OAuth client among them) may hand over a Request rather // than a URL; it goes through untouched apart from the user agent. return (input, init = {}) => { const headers = new Headers(init.headers ?? (input instanceof Request ? input.headers : undefined)); if (!headers.has('user-agent')) headers.set('user-agent', USER_AGENT); return safe(input, { redirect: 'follow', ...init, headers }); };}