From b0380f87985355dfb77a1ec5320f4771ab2fc09d Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 15 Apr 2026 17:01:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(server):=20=E6=94=B9=E7=94=A8=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E5=8C=B9=E9=85=8D=E6=B3=A8=E5=86=8C=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 fasthttp/router 通配符路由替代精确匹配: - path: / 匹配所有子路径如 /sorry/index - path: /api/ 匹配 /api/* 所有子路径 - 路由格式: {path}/{path:*} 此改动确保代理路径下所有子请求都能正确路由到代理处理器, 支持 redirect_rewrite 功能正确处理子路径的重定向改写。 Co-Authored-By: Claude Opus 4.6 --- internal/server/server.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 189e24c..84342bf 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -845,11 +845,20 @@ func (s *Server) registerProxyRoutes(router *handler.Router, serverCfg *config.S // 保存代理实例用于缓存统计 s.proxies = append(s.proxies, p) - router.GET(proxyCfg.Path, p.ServeHTTP) - router.POST(proxyCfg.Path, p.ServeHTTP) - router.PUT(proxyCfg.Path, p.ServeHTTP) - router.DELETE(proxyCfg.Path, p.ServeHTTP) - router.HEAD(proxyCfg.Path, p.ServeHTTP) + // 使用前缀匹配(通配符)注册代理路由 + // path: / 匹配所有子路径如 /sorry/index + // path: /api/ 匹配 /api/* 所有子路径 + routePath := proxyCfg.Path + // 确保通配符路由格式正确 + if !strings.HasSuffix(routePath, "/") && routePath != "/" { + routePath += "/" + } + wildcardPath := routePath + "{path:*}" + router.GET(wildcardPath, p.ServeHTTP) + router.POST(wildcardPath, p.ServeHTTP) + router.PUT(wildcardPath, p.ServeHTTP) + router.DELETE(wildcardPath, p.ServeHTTP) + router.HEAD(wildcardPath, p.ServeHTTP) } }