undici-noproxy
Version:
no_proxy ProxyAgent for undici
67 lines (45 loc) • 1.35 kB
Markdown
> 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.
```
npm i undici-noproxy
```
```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()
```
```
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()
```
```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()
```
MIT licensed