代码之家  ›  专栏  ›  技术社区  ›  Exlord

强制node.exe在Windows 10上引发代理程序

  •  1
  • Exlord  · 技术社区  · 6 年前

    我正在发育 bots 对于 telegram ,我来自伊朗,电报URL在我的国家被阻止,我被迫使用VPN/代理服务器从我的本地dev机器访问电报API。

    但是我的系统上运行的其他应用程序无法使用VPN,所以我不得不使用 proxifier 我可以为需要抛出代理的应用程序定义规则。

    但是node.exe出于某种原因忽略了这些规则,我可以在中看到 NetLimiter 连接来自 C:\Program Files (x86)\nodejs\node.exe 但是,将此路径添加到代理程序的规则中没有任何效果,其他应用程序如电报本身、火狐和…符合这些规则…

    那么,是否有人设法强制node.exe执行throw代理程序?

    我还尝试在主机中用PHP设置代理,但我发现没有一个代理脚本能够处理文件上载。

    我最后的希望是为Apache安装一些模块,并将其用作代理服务器,或者只安装nginx…

    我也试过了 https://github.com/krisives/proxysocket https://github.com/TooTallNate/node-https-proxy-agent 如果没有成功,它只会不断地抛出错误:(

    1 回复  |  直到 6 年前
        1
  •  1
  •   Exlord    6 年前

    好吧,经过数小时的尝试,终于让它与代理程序一起工作了。

    https://github.com/TooTallNate/node-https-proxy-agent

    new HttpsProxyAgent('http://username:password@127.0.0.1:8080')


    更新: 这种方法有问题,所以我用 node-http-proxy 在我的服务器上并连接到它:

    process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
    
    const debug     = require('debug')('app');
    const http      = require('http');
    const httpProxy = require('http-proxy');
    
    const proxy = httpProxy.createProxyServer({
      secure : false
    });
    proxy.on('error', function (e) {
      debug(e);
    });
    
    const server = http.createServer(function(req, res) {
      // You can define here your custom logic to handle the request
      // and then proxy the request.
      proxy.web(req, res, { target: 'https://api.telegram.org', });
    });
    
    server.listen(3333);
    

    只需将所有请求重定向到此服务器即可。