From 60c97e6f606e6d4e2d033a7085d65def6065b615 Mon Sep 17 00:00:00 2001 From: qq_41923622 Date: Mon, 10 Feb 2025 20:25:00 +0800 Subject: [PATCH] Mon Feb 10 20:25:00 CST 2025 inscode --- index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index ab8ad78..94db66c 100644 --- a/index.js +++ b/index.js @@ -2,18 +2,25 @@ const http = require('http'); const httpProxy = require('http-proxy'); // 创建代理服务器实例 const proxy = httpProxy.createProxyServer({ - target: 'https://s.hunlihu.com', // 替换为你要代理的目标服务器地址 + // target: 'https://s.hunlihu.com', // 替换为你要代理的目标服务器地址 changeOrigin: true,// 改变源地址,使目标服务器能正确识别请求来源 autoRewrite: true, - protocolRewrite: 'http', +// protocolRewrite: 'http', }); +// 定义子目录和对应的目标服务器映射 +const subdirectoryMappings = { + 'shunlihu': 'https://s.hunlihu.com', +}; // 创建HTTP服务器 const server = http.createServer((req, res) => { // proxyRes.headers = - console.log(11,req.url, req.headers) - req.headers['origin'] = "https://s.hunlihu.com"; - req.headers['referer'] = "https://s.hunlihu.com"; - console.log(112, req.headers) + proxy.options.target=subdirectoryMappings.shunlihu; + + req.headers['origin'] = subdirectoryMappings.shunlihu; + 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); }); -- GitLab