提交 60c97e6f 编写于 作者: Q qq_41923622

Mon Feb 10 20:25:00 CST 2025 inscode

上级 8d352378
...@@ -2,18 +2,25 @@ const http = require('http'); ...@@ -2,18 +2,25 @@ const http = require('http');
const httpProxy = require('http-proxy'); const httpProxy = require('http-proxy');
// 创建代理服务器实例 // 创建代理服务器实例
const proxy = httpProxy.createProxyServer({ const proxy = httpProxy.createProxyServer({
target: 'https://s.hunlihu.com', // 替换为你要代理的目标服务器地址 // target: 'https://s.hunlihu.com', // 替换为你要代理的目标服务器地址
changeOrigin: true,// 改变源地址,使目标服务器能正确识别请求来源 changeOrigin: true,// 改变源地址,使目标服务器能正确识别请求来源
autoRewrite: true, autoRewrite: true,
protocolRewrite: 'http', // protocolRewrite: 'http',
}); });
// 定义子目录和对应的目标服务器映射
const subdirectoryMappings = {
'shunlihu': 'https://s.hunlihu.com',
};
// 创建HTTP服务器 // 创建HTTP服务器
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
// proxyRes.headers = // proxyRes.headers =
console.log(11,req.url, req.headers) proxy.options.target=subdirectoryMappings.shunlihu;
req.headers['origin'] = "https://s.hunlihu.com";
req.headers['referer'] = "https://s.hunlihu.com"; req.headers['origin'] = subdirectoryMappings.shunlihu;
console.log(112, req.headers) req.headers['referer'] = subdirectoryMappings.shunlihu;
req.headers['host'] = "h5.hunlihu.com";
req.url = req.url.replace(new RegExp(`^\/shunlihu`), '');
console.log(11,req.url, req.headers)
// 将请求代理到目标服务器 // 将请求代理到目标服务器
proxy.web(req, res); proxy.web(req, res);
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册