mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 16:41:54 +08:00
refactor(main): improve CDNJS path matching logic
This commit is contained in:
parent
06f6011b05
commit
830eb864ef
18
main.go
18
main.go
@ -45,14 +45,18 @@ func main() {
|
|||||||
|
|
||||||
// 创建主处理器
|
// 创建主处理器
|
||||||
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mainHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if strings.HasPrefix(r.URL.Path, "/cdnjs") {
|
// 检查是否匹配任何固定路径配置
|
||||||
// CDNJS 请求使用 CDNJS 中间件处理
|
for _, cfg := range cdnjsConfigs {
|
||||||
handler := middleware.CDNJSMiddleware(cdnjsConfigs)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
if strings.HasPrefix(r.URL.Path, cfg.Path) {
|
||||||
handler.ServeHTTP(w, r)
|
// 使用 CDNJS 中间件处理
|
||||||
} else {
|
handler := middleware.CDNJSMiddleware(cdnjsConfigs)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
|
||||||
// 非 CDNJS 请求使用普通代理处理器
|
handler.ServeHTTP(w, r)
|
||||||
proxyHandler.ServeHTTP(w, r)
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果没有匹配的固定路径,使用普通代理处理器
|
||||||
|
proxyHandler.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 对非 CDNJS 请求添加压缩中间件
|
// 对非 CDNJS 请求添加压缩中间件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user