const express = require('express'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); const port = 3001; // 目标服务器地址 const targetUrl = 'http://s.hunlihu.com'; // 创建代理中间件 const apiProxy = createProxyMiddleware('/', { target: targetUrl, changeOrigin: true, pathRewrite: { '^/': '' // 重写请求路径 } }); // 使用代理中间件 app.use(apiProxy); app.listen(port, () => { console.log(`Server is running on port ${port}`); });