https://github.com/commenthol/undici-noproxy
https://github.com/commenthol/undici-noproxy
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/commenthol/undici-noproxy
- Owner: commenthol
- License: mit
- Created: 2022-03-24T06:25:21.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T07:18:19.000Z (over 1 year ago)
- Last Synced: 2025-10-08T22:52:20.420Z (9 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# undici-noproxy
> no_proxy ProxyAgent for undici
An [undici ProxyAgent](https://undici.nodejs.org/#/docs/api/ProxyAgent) which considers `http(s)_proxy` and `no_proxy` env-vars or settings.
# usage
```
npm i undici-noproxy
```
## proxy settings in code
```js
import { request } from 'undici'
import { NoProxyAgent } from 'undici-noproxy'
const proxyAgent = new NoProxyAgent({
uri: 'http://my-http.proxy',
protocol: 'http',
noProxy: 'localhost,.my.domain'
})
const res = await request('https://httpbin.org/anything', { dispatcher: proxyAgent })
const json = await res.body.json()
proxyAgent.close()
```
## proxy settings via env vars
```
http_proxy=http://my-http.proxy
no_proxy=localhost,.my.domain
```
`NoProxyAgent` considers the settings from the given env-vars...
```js
import { request } from 'undici'
import { NoProxyAgent } from 'undici-noproxy'
const proxyAgent = new NoProxyAgent()
const res = await request('https://httpbin.org/anything', { dispatcher: proxyAgent })
const json = await res.body.json()
proxyAgent.close()
```
## with global dispatcher
```js
import { fetch, setGlobalDispatcher } from 'undici'
import { NoProxyAgent } from 'undici-noproxy'
const proxyAgent = new NoProxyAgent()
setGlobalDispatcher(proxyAgent)
const res = await fetch(url)
const json = await res.json()
```
# license
MIT licensed