Skip to content

Commit 83bd275

Browse files
committed
Add documentation and npm publishing prep
Documentation (ReadTheDocs): - Add MkDocs configuration with Material theme - Create comprehensive docs for all supported libraries - Add getting-started guide, core API reference, and testing guide - Configure .readthedocs.yaml for hosted documentation npm Publishing Prep: - Add TypeScript type definitions (types/index.d.ts) - Update package.json with proper exports, files, and metadata - Add .npmignore to exclude dev files from package - Add prepublishOnly script to run tests before publish Documentation pages: - index.md - Overview and quick start - getting-started.md - Installation and examples - axios.md - axios library reference - node-fetch.md - node-fetch library reference - got.md - got library reference - undici.md - undici library reference - superagent.md - superagent library reference - core-api.md - Core ProxyHeadersAgent API - testing.md - Test harness documentation Made-with: Cursor
1 parent 94043a4 commit 83bd275

15 files changed

Lines changed: 2324 additions & 12 deletions

.npmignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Development files
2+
.git/
3+
.github/
4+
.gitignore
5+
6+
# Documentation source
7+
docs/
8+
mkdocs.yml
9+
.readthedocs.yaml
10+
11+
# Research and planning
12+
LIBRARY_RESEARCH.md
13+
IMPLEMENTATION_PRIORITY.md
14+
15+
# Test files
16+
test/
17+
coverage/
18+
.nyc_output/
19+
20+
# IDE
21+
.vscode/
22+
.idea/
23+
*.swp
24+
*.swo
25+
26+
# OS files
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Development config
31+
.eslintrc*
32+
.prettierrc*
33+
.editorconfig
34+
35+
# Logs
36+
*.log
37+
npm-debug.log*
38+
39+
# Build artifacts not needed
40+
*.tgz

.readthedocs.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Read the Docs configuration file for MkDocs
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html
3+
4+
version: 2
5+
6+
build:
7+
os: ubuntu-22.04
8+
tools:
9+
python: "3.11"
10+
11+
mkdocs:
12+
configuration: mkdocs.yml
13+
14+
python:
15+
install:
16+
- requirements: docs/requirements.txt

docs/axios.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# axios
2+
3+
[axios](https://axios-http.com/) is the most popular HTTP client for JavaScript. This page describes how to use axios with proxies and how to send and receive custom proxy headers.
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
Install the packages:
10+
11+
```bash
12+
npm install javascript-proxy-headers axios
13+
```
14+
15+
### Quick Example
16+
17+
```javascript
18+
import { createProxyAxios } from 'javascript-proxy-headers/axios';
19+
20+
// Create a configured axios instance
21+
const client = await createProxyAxios({
22+
proxy: 'http://user:pass@proxy.example.com:8080',
23+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
24+
});
25+
26+
// Make requests
27+
const response = await client.get('https://httpbin.org/ip');
28+
29+
// Access response data
30+
console.log(response.data);
31+
32+
// Access proxy response headers (merged into response.headers)
33+
console.log(response.headers['x-proxymesh-ip']);
34+
```
35+
36+
## API Reference
37+
38+
### createProxyAxios(options)
39+
40+
Creates an axios instance configured with proxy header support.
41+
42+
**Parameters:**
43+
44+
| Name | Type | Description |
45+
|------|------|-------------|
46+
| `options.proxy` | `string` | Proxy URL (e.g., `http://user:pass@proxy:8080`) |
47+
| `options.proxyHeaders` | `Object` | Headers to send to the proxy |
48+
| `options.onProxyConnect` | `Function` | Callback when CONNECT completes: `(headers) => void` |
49+
| `options.axiosOptions` | `Object` | Additional axios instance options |
50+
51+
**Returns:** `Promise<AxiosInstance>` - Configured axios instance
52+
53+
**Example:**
54+
55+
```javascript
56+
import { createProxyAxios } from 'javascript-proxy-headers/axios';
57+
58+
const client = await createProxyAxios({
59+
proxy: 'http://proxy:8080',
60+
proxyHeaders: {
61+
'X-ProxyMesh-Country': 'US',
62+
'X-ProxyMesh-Session': 'my-session'
63+
},
64+
onProxyConnect: (headers) => {
65+
console.log('Connected via:', headers.get('x-proxymesh-ip'));
66+
},
67+
axiosOptions: {
68+
timeout: 30000,
69+
headers: { 'User-Agent': 'MyApp/1.0' }
70+
}
71+
});
72+
```
73+
74+
### Convenience Functions
75+
76+
For one-off requests, you can use the convenience functions:
77+
78+
```javascript
79+
import { get, post } from 'javascript-proxy-headers/axios';
80+
81+
// GET request
82+
const response = await get('https://httpbin.org/ip', {
83+
proxy: 'http://proxy:8080',
84+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
85+
});
86+
87+
// POST request
88+
const response = await post('https://httpbin.org/post', { key: 'value' }, {
89+
proxy: 'http://proxy:8080',
90+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
91+
});
92+
```
93+
94+
## Accessing Proxy Headers
95+
96+
Proxy response headers are automatically merged into `response.headers`:
97+
98+
```javascript
99+
const response = await client.get('https://httpbin.org/ip');
100+
101+
// Proxy headers are available in response.headers
102+
const proxyIp = response.headers['x-proxymesh-ip'];
103+
const proxyCountry = response.headers['x-proxymesh-country'];
104+
```
105+
106+
You can also access the underlying agent to get the last proxy headers:
107+
108+
```javascript
109+
const client = await createProxyAxios({
110+
proxy: 'http://proxy:8080',
111+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
112+
});
113+
114+
await client.get('https://httpbin.org/ip');
115+
116+
// Access via the agent
117+
console.log(client.proxyAgent.lastProxyHeaders);
118+
```
119+
120+
## All Request Methods
121+
122+
The created axios instance supports all standard methods:
123+
124+
```javascript
125+
const client = await createProxyAxios({
126+
proxy: 'http://proxy:8080',
127+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
128+
});
129+
130+
// GET
131+
const r1 = await client.get('https://api.example.com/data');
132+
133+
// POST
134+
const r2 = await client.post('https://api.example.com/data', { key: 'value' });
135+
136+
// PUT
137+
const r3 = await client.put('https://api.example.com/data/1', { key: 'updated' });
138+
139+
// DELETE
140+
const r4 = await client.delete('https://api.example.com/data/1');
141+
142+
// PATCH
143+
const r5 = await client.patch('https://api.example.com/data/1', { key: 'patched' });
144+
145+
// HEAD
146+
const r6 = await client.head('https://api.example.com/data');
147+
```
148+
149+
## Using with Existing Code
150+
151+
If you have existing axios code, you can create a configured instance and use it as a drop-in replacement:
152+
153+
```javascript
154+
// Before (standard axios)
155+
import axios from 'axios';
156+
const response = await axios.get('https://api.example.com/data');
157+
158+
// After (with proxy headers)
159+
import { createProxyAxios } from 'javascript-proxy-headers/axios';
160+
const axios = await createProxyAxios({
161+
proxy: process.env.PROXY_URL,
162+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
163+
});
164+
const response = await axios.get('https://api.example.com/data');
165+
```
166+
167+
## Error Handling
168+
169+
```javascript
170+
import { createProxyAxios } from 'javascript-proxy-headers/axios';
171+
172+
const client = await createProxyAxios({
173+
proxy: 'http://proxy:8080',
174+
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
175+
});
176+
177+
try {
178+
const response = await client.get('https://httpbin.org/ip');
179+
console.log(response.data);
180+
} catch (error) {
181+
if (error.name === 'ConnectError') {
182+
// Proxy CONNECT failed
183+
console.error('Proxy error:', error.statusCode, error.statusMessage);
184+
console.error('Proxy headers:', error.proxyHeaders);
185+
} else if (error.response) {
186+
// Target server error
187+
console.error('Server error:', error.response.status);
188+
} else {
189+
// Network error
190+
console.error('Network error:', error.message);
191+
}
192+
}
193+
```

0 commit comments

Comments
 (0)