Skip to content

Commit

Permalink
[docs] Add example of dns lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
01101sam committed Sep 16, 2023
1 parent 358ec31 commit b40a317
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ npm i @sam01101/node-proxy-agent
Examples
--------

### Common

#### DNS lookup example

``` js
import fetch from "node-fetch";
import {HttpsProxyAgent} from '@sam01101/node-proxy-agent';

(async () => {
// HTTP/HTTPS proxy to connect to
const proxy = process.env.http_proxy || 'http://168.63.76.32:3128';
console.log('using proxy server %j', proxy);

// HTTPS endpoint for the proxy to connect to
const endpoint = process.argv[2] || 'https://one.one.one.one/cdn-cgi/trace';
console.log('attempting to GET %j', endpoint);

const response = await fetch(endpoint, {
// create an instance of the `HttpsProxyAgent` class with the proxy server information
agent: new HttpsProxyAgent(proxy, {
// Note: options is empty but reserved for backward compatibility
lookup: (hostname, options, callback) => {
console.log(`Lookup ${hostname}`);
return callback(null, '1.1.1.1', 4);
})
});
console.log(`HTTP Status: ${response.status} OK: ${response.ok}`);
})();
```
### HttpsProxyAgent
#### `https` module example (TypeScript)
Expand Down

0 comments on commit b40a317

Please sign in to comment.