{"_id":"@constructive-io/fetch","_rev":"6-0013b57b5db26a64dd8fb1bf734041ba","name":"@constructive-io/fetch","dist-tags":{"latest":"1.2.2"},"versions":{"1.0.0":{"name":"@constructive-io/fetch","version":"1.0.0","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"author":"Constructive <developers@constructive.io>","license":"MIT","_id":"@constructive-io/fetch@1.0.0","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"homepage":"https://github.com/constructive-io/dev-utils","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"d35dd38279456a49066071ab35dc215c282f44d3","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.0.0.tgz","fileCount":12,"integrity":"sha512-4W2lnDOzFiYRBLNit4wzSHFZu8eO68W6RIxBApwFIhChGfgdMwI9H68Ant3B9CXnIhxq4peY3mSCC2krS67ojw==","signatures":[{"sig":"MEYCIQCRpuADss0g4geiZFuPh6PhYYcm8L3ZwwWST5ZhFFOY2AIhAIFFWccJGjx3d9J9vP52Y/tjrO1odsoOS+vB/ASgYizj","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15988},"main":"index.js","types":"index.d.ts","module":"esm/index.js","gitHead":"804b104439dceda895963e3f40a523473d5a8f98","scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"pyramation","email":"pyramation@gmail.com"},"repository":{"url":"https://github.com/constructive-io/dev-utils","type":"git"},"_npmVersion":"lerna/8.2.4/node@v22.13.1+arm64 (darwin)","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"_nodeVersion":"22.13.1","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"tmp":"tmp/fetch_1.0.0_1777366350226_0.20967491793740134","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@constructive-io/fetch","version":"1.1.1","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"author":"Constructive <developers@constructive.io>","license":"MIT","_id":"@constructive-io/fetch@1.1.1","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"homepage":"https://github.com/constructive-io/dev-utils","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"fa1543b3e93e4dee8cc4b61ccf41282647f810aa","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.1.1.tgz","fileCount":18,"integrity":"sha512-kpus6sqQwMUTBNpqYvSejG27HJXDucV+BQUNUg3T5U92Qy94Q6of7OhbovICteDMmgcRKCdc5S2e2pXnIY8L5A==","signatures":[{"sig":"MEQCIAxA77p8HB3CFZnGGINbeMWVjxkuT4M70ljXKStGXly+AiB0tDldNCW/3AI56UsOCtFmD4RblCdfllR85F5rAwCgIQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19368},"main":"index.js","types":"index.d.ts","module":"esm/index.js","browser":{"./index.js":"./index.browser.js","./esm/index.js":"./esm/index.browser.js","./localhost-fetch.js":"./localhost-fetch.browser.js","./esm/localhost-fetch.js":"./esm/localhost-fetch.browser.js"},"gitHead":"304fcae0a8ea59d97f00f8246979a061fde85a66","scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"pyramation","email":"pyramation@gmail.com"},"repository":{"url":"https://github.com/constructive-io/dev-utils","type":"git"},"_npmVersion":"lerna/8.2.4/node@v22.13.1+arm64 (darwin)","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"_nodeVersion":"22.13.1","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"tmp":"tmp/fetch_1.1.1_1779397167871_0.9098879593002143","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"@constructive-io/fetch","version":"1.1.2","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"author":"Constructive <developers@constructive.io>","license":"MIT","_id":"@constructive-io/fetch@1.1.2","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"homepage":"https://github.com/constructive-io/dev-utils","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"5c68ab6264402c0075d727298a5511f578fcbac2","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.1.2.tgz","fileCount":18,"integrity":"sha512-Iryvvf51JupNXMhIT8FYbO0zSgkECcEQAn2fiAZCqxg0qLyYIbDVshn5fVf4jlQW126Jo9FHCSWT0Uiw9+kQ3Q==","signatures":[{"sig":"MEUCIC4zs7NAHpIY7QHuWfBOHBiAlloPqk6ZHQs8F4/HXrpKAiEAibAZvzNqwjXPNgosxHyHwNc8NoebeHDQ+FiHylu9c84=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19056},"main":"index.js","types":"index.d.ts","module":"esm/index.js","browser":{"./index.js":"./index.browser.js","./esm/index.js":"./esm/index.browser.js","./localhost-fetch.js":"./localhost-fetch.browser.js","./esm/localhost-fetch.js":"./esm/localhost-fetch.browser.js"},"gitHead":"2985d68020ec7d1eeae9a839bdb7ebb68727dd55","scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"pyramation","email":"pyramation@gmail.com"},"repository":{"url":"https://github.com/constructive-io/dev-utils","type":"git"},"_npmVersion":"lerna/8.2.4/node@v22.13.1+arm64 (darwin)","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"_nodeVersion":"22.13.1","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"tmp":"tmp/fetch_1.1.2_1785533376554_0.5943691742917467","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"name":"@constructive-io/fetch","version":"1.2.0","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"author":"Constructive <developers@constructive.io>","license":"MIT","_id":"@constructive-io/fetch@1.2.0","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"homepage":"https://github.com/constructive-io/dev-utils","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"c66517ffbcb940bd7bdca8fceb62463a0cb7bbe4","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.2.0.tgz","fileCount":18,"integrity":"sha512-Np5D2MONxZDgTULEX4vGxe2Ap4hZsd8ss9+GzkvED02eV71uPAswQzG6a0g3ppxQhqguKJvS5lGnUWtQ/u4y4g==","signatures":[{"sig":"MEYCIQDGFKR3voUV1tGNWtCv+oCjOeflrReEVom4mcNmlqB9dAIhAJiScINV4qwhOMjb71j1jda+z6WFnfacQZ6lNDfOn41m","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25045},"main":"index.js","types":"index.d.ts","module":"esm/index.js","browser":{"./index.js":"./index.browser.js","./esm/index.js":"./esm/index.browser.js","./localhost-fetch.js":"./localhost-fetch.browser.js","./esm/localhost-fetch.js":"./esm/localhost-fetch.browser.js"},"gitHead":"a934e620c593aa0a518868bafdce35bcd0a68705","scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"pyramation","email":"pyramation@gmail.com"},"repository":{"url":"https://github.com/constructive-io/dev-utils","type":"git"},"_npmVersion":"lerna/8.2.4/node@v22.13.1+arm64 (darwin)","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"_nodeVersion":"22.13.1","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"tmp":"tmp/fetch_1.2.0_1786141392394_0.5564649918335538","host":"s3://npm-registry-packages-npm-production"}},"1.2.1":{"name":"@constructive-io/fetch","version":"1.2.1","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"author":{"name":"Constructive","email":"developers@constructive.io"},"license":"MIT","_id":"@constructive-io/fetch@1.2.1","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"homepage":"https://github.com/constructive-io/dev-utils","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"f0656144913f3aca94202732aea74a40d82fe4f6","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.2.1.tgz","fileCount":18,"integrity":"sha512-bjUG9tap5Vq2Fb/FvIC0I/XoLX8B+xjxrFs4xSbLrF/hAQDXmQ9IFnJ9bYuK3erGJN/BjOxu0cWc5cfsFUF8xg==","signatures":[{"sig":"MEUCIQCKRPisLYhyi01S9QUWAhzQ4aihKBdhm48WvaEmvJfq9wIgYf0oKT8HKvzdxnZSjb3KJPt+gIPqean5kjQf8wnohaQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIBwnRtQyFtorSUpaCd/0Gj/MsK2Zzu4kPkLTqOYGVdpdAiArMGrilu2oA7YMfNLnGi3tKEaVg7uXHcbvXReGEX9nqQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24948},"main":"index.js","_from":"file:/tmp/packs-HjyxSq/constructive-io-fetch-1.2.1.tgz","types":"index.d.ts","module":"esm/index.js","browser":{"./index.js":"./index.browser.js","./esm/index.js":"./esm/index.browser.js","./localhost-fetch.js":"./localhost-fetch.browser.js","./esm/localhost-fetch.js":"./esm/localhost-fetch.browser.js"},"scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"61512090-099f-4346-a14c-4eb6ae9b12e4"}},"_resolved":"/tmp/packs-HjyxSq/constructive-io-fetch-1.2.1.tgz","_integrity":"sha512-bjUG9tap5Vq2Fb/FvIC0I/XoLX8B+xjxrFs4xSbLrF/hAQDXmQ9IFnJ9bYuK3erGJN/BjOxu0cWc5cfsFUF8xg==","repository":{"url":"git+https://github.com/constructive-io/dev-utils.git","type":"git"},"_npmVersion":"11.21.3","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"_nodeVersion":"24.22.3","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"tmp":"tmp/fetch_1.2.1_1795409811834_0.5565368249659797","host":"s3://npm-registry-packages-npm-production"}},"1.2.2":{"_id":"@constructive-io/fetch@1.2.2","bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"dist":{"shasum":"70596c1b0a30b25c48e2e50cc1995b218236df7a","tarball":"https://registry.npmjs.org/@constructive-io/fetch/-/fetch-1.2.2.tgz","fileCount":18,"integrity":"sha512-4hUZvY9BrRSBgfHazkFtU67k00Y9aoh60RS/MedkF2HpdpWmwVYCUo6+Ck24KMSuKIFgNgjfhTtZPkrIGn2KmQ==","signatures":[{"sig":"MEYCIQC1aKYpdRHTSvUsLF7ZQrMX0zjD+hztbx2GpFFulOmwjQIhAIUt6gW0gdoQENoBL/l8hmpYh5u9/2bseVNkw1P1fllB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDIyuMaUudHyPU3yDF7icnwtO7xFNUrDxZFCBP72chp0wIhANH91xnKUTYswKGkbGhsTDCeJ9oeFD5G8U3tlnu0uM4r"}],"unpackedSize":24948},"main":"index.js","name":"@constructive-io/fetch","_from":"file:/home/runner/work/_temp/packs/package-8.tgz","types":"index.d.ts","author":{"name":"Constructive","email":"developers@constructive.io"},"module":"esm/index.js","browser":{"./index.js":"./index.browser.js","./esm/index.js":"./esm/index.browser.js","./localhost-fetch.js":"./localhost-fetch.browser.js","./esm/localhost-fetch.js":"./esm/localhost-fetch.browser.js"},"license":"MIT","scripts":{"copy":"makage assets","lint":"eslint . --fix","test":"jest","build":"makage build","clean":"makage clean","test:watch":"jest --watch"},"version":"1.2.2","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"61512090-099f-4346-a14c-4eb6ae9b12e4"}},"homepage":"https://github.com/constructive-io/dev-utils","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"_resolved":"/home/runner/work/_temp/packs/package-8.tgz","_integrity":"sha512-4hUZvY9BrRSBgfHazkFtU67k00Y9aoh60RS/MedkF2HpdpWmwVYCUo6+Ck24KMSuKIFgNgjfhTtZPkrIGn2KmQ==","repository":{"url":"git+https://github.com/constructive-io/dev-utils.git","type":"git"},"_npmVersion":"11.21.3","description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","directories":{},"maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"_nodeVersion":"24.22.3","publishConfig":{"access":"public","directory":"dist"},"_hasShrinkwrap":false,"devDependencies":{"makage":"0.1.10"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetch_1.2.2_1795744799318_0.3314492067103124"}}},"time":{"created":"2026-04-28T08:52:30.127Z","modified":"2026-11-27T01:59:59.567Z","1.0.0":"2026-04-28T08:52:30.360Z","1.1.1":"2026-05-21T20:59:28.026Z","1.1.2":"2026-07-31T21:29:36.746Z","1.2.0":"2026-08-07T22:23:12.656Z","1.2.1":"2026-11-23T04:56:51.924Z","1.2.2":"2026-11-27T01:59:59.410Z"},"bugs":{"url":"https://github.com/constructive-io/dev-utils/issues"},"author":{"name":"Constructive","email":"developers@constructive.io"},"license":"MIT","homepage":"https://github.com/constructive-io/dev-utils","keywords":["fetch","isomorphic","localhost","node","browser","dns","host-header"],"repository":{"url":"git+https://github.com/constructive-io/dev-utils.git","type":"git"},"description":"Isomorphic fetch wrapper — resolves *.localhost subdomains and preserves Host headers across Node.js and browsers","maintainers":[{"name":"zetazz","email":"zetazhenzhi@gmail.com"},{"name":"pyramation","email":"pyramation@gmail.com"},{"name":"phatg","email":"phatghaa@gmail.com"}],"readme":"# @constructive-io/fetch\n\nIsomorphic fetch that resolves `*.localhost` subdomains and preserves `Host` headers across Node.js and browsers.\n\n## Why\n\nNode.js has three issues with `*.localhost` subdomains:\n\n1. **DNS** — `fetch('http://auth.localhost:3000/')` throws `ENOTFOUND` because Node (undici) doesn't resolve `*.localhost` to loopback ([nodejs/node#50871](https://github.com/nodejs/node/issues/50871)).\n2. **Host header** — Node's fetch treats `Host` as a forbidden header and silently drops it, breaking server-side subdomain routing.\n3. **Loopback family** — `localhost` commonly resolves to IPv6 `::1` first, but many local dev ingresses (kind, Docker's port publishing) listen on IPv4 only, so a DNS-driven connect reaches `::1` and fails on setups without Node's Happy-Eyeballs fallback.\n\nBrowsers handle all three correctly. This package fixes them in Node by using `node:http`/`node:https` for `*.localhost` URLs — pinning the connect to the loopback interface (IPv4 by default) while preserving the original `Host` header — and passing everything else through to `globalThis.fetch`.\n\n## Install\n\n```bash\nnpm install @constructive-io/fetch\n```\n\n## Usage\n\n```ts\nimport { createFetch } from '@constructive-io/fetch';\n\nconst fetch = createFetch();\n\n// Works in Node.js — DNS resolves, Host header preserved\nconst res = await fetch('http://auth.localhost:3000/graphql', {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: JSON.stringify({ query: '{ currentUser { id } }' }),\n});\n```\n\n## API\n\n### `createFetch(options?: CreateFetchOptions): typeof globalThis.fetch`\n\nReturns a fetch function. In Node.js, `*.localhost` URLs are handled via `node:http`/`node:https`. Everything else delegates to `globalThis.fetch`. The default-configuration result is cached.\n\n**`CreateFetchOptions`**\n\n- `loopback?: '127.0.0.1' | '::1' | false` — how to reach the loopback interface for `*.localhost` URLs (Node only). The connect is pinned to this address, removing DNS from the loopback hop; the original `Host` header is preserved so subdomain routing still works.\n  - `'127.0.0.1'` (default) — pin the IPv4 loopback.\n  - `'::1'` — pin the IPv6 loopback.\n  - `false` — no pin; rewrite the host to `localhost` and rely on system DNS (the pre-1.2 behavior).\n\n  Ignored in browsers, which resolve `*.localhost` natively.\n\n```ts\n// IPv6-only loopback\nconst fetch = createFetch({ loopback: '::1' });\n```\n\n### `isLocalhostSubdomain(hostname: string): boolean`\n\nReturns `true` for `*.localhost` subdomains (e.g. `auth.localhost`), `false` for bare `localhost` and everything else.\n\n---\n\n## Development\n\n### Setup\n\n1. Clone the repository:\n\n```bash\ngit clone https://github.com/constructive-io/dev-utils.git\n```\n\n2. Install dependencies:\n\n```bash\ncd dev-utils\npnpm install\npnpm build\n```\n\n3. Test the package of interest:\n\n```bash\ncd packages/<packagename>\npnpm test:watch\n```\n\n## Credits\n\n**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**\n\n## Disclaimer\n\nAS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED \"AS IS\", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.\n\nNo developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.\n","readmeFilename":"README.md"}