强制 node.exe 在 windows 10 上抛出代理

force node.exe to go throw proxifier on windows 10

我正在开发 bots for telegram,我来自伊朗,电报 url 在我的国家被封锁,我被迫使用 VPN/Proxy 服务器访问电报 api从我本地的开发机器。

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

但是 node.exe 出于某种原因忽略了这个规则,我可以在 NetLimiter 中看到连接来自 C:\Program Files (x86)\nodejs\node.exe,但是将这个路径添加到 proxifier 的规则没有效果,其他应用程序,如 telegram 本身和 firefox 以及...适用于这些规则...

那么有没有人设法强迫 node.exe 去抛出代理程序?

我还尝试在主机中使用 php 设置代理,但我发现 none 的代理脚本能够处理文件上传

我最后的希望是为 apache 安装一些模块并将其用作代理或者只安装 nginx ...

我也试过 https://github.com/krisives/proxysocket and https://github.com/TooTallNate/node-https-proxy-agent 但没有成功,它一直在抛出错误:(

好的,经过几个小时的尝试终于让这个与代理一起工作。

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);

并且只是将所有请求重定向到此服务器。