Skip to content

Commit

Permalink
upd proxy agent deps, see #123
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Oct 9, 2023
1 parent dec0f13 commit e60fd58
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 57 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ Google Translate has request limits. If too many requests are made from the same

```ts
import { translate } from '@vitalets/google-translate-api';
import createHttpProxyAgent from 'http-proxy-agent';
import { HttpProxyAgent } from 'http-proxy-agent';

const agent = createHttpProxyAgent('http://103.152.112.162:80');
const agent = new HttpProxyAgent('http://103.152.112.162:80');
const { text } = await translate('Привет, мир!', {
to: 'en',
fetchOptions: { agent },
});
```
See [examples/with-proxy.ts] for more details.

> Available proxy list you can find [here](https://free-proxy-list.net/) (with `yes` in Google column).
> Available proxy list you can find [here](https://free-proxy-list.net/) (with `anonymous` in **Anonymity* and `yes` in *Google* columns).
Common pattern for selecting proxy is following:
```ts
Expand Down
4 changes: 2 additions & 2 deletions examples/with-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* npx ts-node-esm examples/with-proxy.ts 8.210.83.33:80
*/
import { RequestInit } from 'node-fetch';
import createHttpProxyAgent from 'http-proxy-agent';
import { HttpProxyAgent } from 'http-proxy-agent';
import { translate } from '../src/index.js';

const proxy = process.argv[2];
Expand All @@ -23,7 +23,7 @@ async function translateWithProxy(sourceText: string) {
const ac = new AbortController();
const timer = setTimeout(() => ac.abort(), timeoutMs);
const fetchOptions = {
agent: createHttpProxyAgent(`http://${proxy}`),
agent: new HttpProxyAgent(`http://${proxy}`),
signal: ac.signal,
} as Partial<RequestInit>;
try {
Expand Down
79 changes: 31 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"@typescript-eslint/parser": "^5.39.0",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.2",
"markdown-toc": "^1.2.0",
"mocha": "^10.1.0",
"np": "^7.6.2",
Expand Down
4 changes: 2 additions & 2 deletions test/specs/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import createHttpProxyAgent from 'http-proxy-agent';
import { HttpProxyAgent } from 'http-proxy-agent';
import { extractTooManyRequestsInfo } from '../../src/helpers.js';

it('translate to en', async () => {
Expand Down Expand Up @@ -42,7 +42,7 @@ it('invalid host', async () => {
it('proxy', async () => {
const proxyUrl = process.env.PROXY;
if (proxyUrl) {
const agent = createHttpProxyAgent(proxyUrl);
const agent = new HttpProxyAgent(proxyUrl);
const { text } = await translate('Ia hala ana mai o ka waa o Pele', {
fetchOptions: { agent }
});
Expand Down

0 comments on commit e60fd58

Please sign in to comment.