node.js - 创建一个支持 https 的 HTTP 代理服务器,并使用另一个代理服务器使用 nodejs 提供响应
问题描述
我需要帮助使用 node js 创建代理服务器以与 firefox 一起使用。
最终目标是创建一个代理服务器,该服务器将通过另一个代理服务器(HTTP / SOCKS)隧道传输流量并将响应返回给firefox。像这样
我想保留从代理服务器收到的原始响应,也想支持 https 网站。
这是我想出的代码。
var http = require('http');
var request = require("request");
http.createServer(function(req, res){
const resu = request(req.url, {
// I wanna Fetch the proxy From database and use it here
proxy: "<Proxy URL>"
})
req.pipe(resu);
resu.pipe(res);
}).listen(8080);
但它有两个问题。
- 它不支持 https 请求。
- 它也不支持 SOCKS 4/5 代理。
编辑:我尝试使用此模块创建代理服务器。https://github.com/http-party/node-http-proxy 但问题是我们无法指定任何外部代理服务器来发送连接。
解决方案
您必须使用一些中间件,例如 http-proxy 模块。
此处的文档:https ://www.npmjs.com/package/http-proxy
使用安装它npm install node-http-proxy
这也可能有帮助:如何在 node.js 中创建一个简单的 http 代理?
推荐阅读
- javascript - 如何将复选框的选定值插入到输入中?
- javascript - 带有句法着色的 Json Pretty Print
- android - 无法使用自定义 gradle 任务更改清单标签
- docker - 使用 docker-compose 时有一个奇怪的问题
- php - Symfony-Finder 无法打开目录
- typescript - 如何解决这种类型分配错误(从目标函数到 `observe` )?
- php - 在 Woocommerce 3 中获取并显示可变产品价格范围
- kettle - 如何解决pentaho数据集成错误
- authentication - (graphql,prisma)我如何在登录(登录)时忽略(通过)检查身份验证?
- cron - crontab -; 命令