plainheart / bing-translate-api

A simple and free API for Bing & Microsoft Translator for Node.js
https://github.com/plainheart/bing-translate-api
MIT License
156 stars 28 forks source link

please show us a proxy example #33

Closed RwGrid closed 7 months ago

RwGrid commented 9 months ago

with got compatible and which got version to use and how to define proxy agent

sabatale commented 9 months ago
import { HttpProxyAgent } from "hpagent";
import { translate } from "bing-translate-api";

var myproxy = new HttpProxyAgent({
        keepAlive: true,
        keepAliveMsecs: 1000,
        maxSockets: 256,
        maxFreeSockets: 256,
        proxy: ...proxyUrl...
    });

const result = await translate(text, source, destination, false, false, agent, { http: myproxy });
stephanebouget commented 4 months ago

Hi,

@plainheart, is there a way to use MET translate with a proxy ?

I tried to use :

import { HttpsProxyAgent } from "hpagent";

const proxy = new HttpsProxyAgent({
    keepAlive: true,
    keepAliveMsecs: 1000,
    maxSockets: 256,
    maxFreeSockets: 256,
    proxy: config.proxy,
  });

  MET.translate(
    req?.body?.text,
    req?.body?.langIn || "auto-detect",
    req?.body?.langOut,
    {
        https: proxy,
    }
  )
    .then((data: any) => {
      console.log(data);
      res.status(200).send(data);
    })
    .catch((error: any) => {
      console.error(error);
      res.status(400).send(error);
    });

but without success (it works with bing)

thank you !

plainheart commented 4 months ago

@stephanebouget Hi, might be like this

import { HttpsProxyAgent } from 'hpagent'

const httpsAgent = new HttpsProxyAgent({
  // ...
})

MET.translate('Hi', null, 'zh-Hans', {
  gotOptions: {
    agent: {
      https: httpsAgent
    }
  }
})