Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ npx @humanwhocodes/proxy-fetch-server

The server is configured using environment variables:

- **FETCH_PROXY** (conditionally required) - A universal proxy URI that will be used for both HTTP and HTTPS requests. When set, this supersedes both `http_proxy` and `https_proxy`, allowing you to configure the proxy just for the fetch request rather than the whole process.
- **http_proxy** (conditionally required) - The proxy server to use for requests that use the http protocol
- **https_proxy** (conditionally required) - The proxy server to use for requests that use the https protocol
- **no_proxy** (optional) - A comma-delimited list of hostnames or hostname:port entries that should bypass using the configured proxy completely. If a hostname begins with a dot (.) then it applies to all subdomains. For instance `.humanwhocodes.com` applies to `humanwhocodes.com`, `www.humanwhocodes.com`, `newsletter.humanwhocodes.com`, etc.
Expand All @@ -38,7 +39,7 @@ The server is configured using environment variables:
- **PROXY_TOKEN** (optional) - The token that the proxy expects
- **PROXY_TOKEN_TYPE** (optional) - The token type prefix for the proxy (default: "Bearer")

Either `http_proxy` or `https_proxy` is required.
Either `FETCH_PROXY` or at least one of `http_proxy` and `https_proxy` is required.

Example:

Expand All @@ -53,6 +54,18 @@ PROXY_TOKEN_TYPE=Bearer \
npx @humanwhocodes/proxy-fetch-server
```

Or, using `FETCH_PROXY` to set both HTTP and HTTPS proxy to the same value:

```shell
FETCH_PROXY=http://proxy.example.com:8080 \
no_proxy=localhost,.internal.com \
PROXY_FETCH_KEY=my-secret-key \
PORT=3000 \
PROXY_TOKEN=proxy-secret \
PROXY_TOKEN_TYPE=Bearer \
npx @humanwhocodes/proxy-fetch-server
```

### Making Requests

Send a POST request to the root endpoint (`/`) with:
Expand Down
7 changes: 4 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { createApp } from "./app.js";
// Get configuration from environment variables
const key = process.env.PROXY_FETCH_KEY;
const port = parseInt(process.env.PORT || "8080", 10);
const httpProxy = process.env.http_proxy;
const httpsProxy = process.env.https_proxy;
const fetchProxyUri = process.env.FETCH_PROXY;
const httpProxy = fetchProxyUri || process.env.http_proxy;
const httpsProxy = fetchProxyUri || process.env.https_proxy;
const noProxyEnv = process.env.no_proxy;
const proxyToken = process.env.PROXY_TOKEN;
const proxyTokenType = process.env.PROXY_TOKEN_TYPE;
Expand All @@ -28,7 +29,7 @@ const noProxy = noProxyEnv
// Validate required configuration
if (!httpProxy && !httpsProxy) {
console.error(
"Error: Either http_proxy or https_proxy environment variable is required",
"Error: Either FETCH_PROXY, http_proxy, or https_proxy environment variable is required",
);
process.exit(1);
}
Expand Down