https://github.com/commenthol/uses-proxy
https://github.com/commenthol/uses-proxy
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/commenthol/uses-proxy
- Owner: commenthol
- License: mit
- Created: 2022-03-24T06:24:41.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T07:13:34.000Z (over 1 year ago)
- Last Synced: 2025-07-07T05:18:35.599Z (12 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uses-proxy
> Check if a url shall be proxied through a http(s) proxy
Implements the recommendations from https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/
Detects and uses `http(s)_proxy` and `no_proxy` environment variables.
- Environment variables lowercase precedence. `no_proxy` comes before `NO_PROXY`
- Matches suffixes
- Strips leading `.`
- `*` matches all hosts
- No support for regexes.
- Supports CIDR Blocks
- Does not match loopback IPs
# usage
```
npm i uses-proxy
```
```js
import { usesProxy, shouldProxy } from 'uses-proxy'
const {
proxyUri, // proxy uri from https_proxy, http_proxy, ...
protocol, // used protocol of proxy
noProxy // no_proxy env var content
} = usesProxy()
const matcher = shouldProxy({
proxyUri,
noProxy: noProxy || 'localhost, tempuri.org'
})
matcher('localhost') // >> false
matcher('test.com') // >> true
matcher('test.tempuri.org') // >> false
matcher('tempuri.org') // >> false
```
# license
MIT licensed