From 0d300a35404c9403c56ed47f4c8c7c7b41c28087 Mon Sep 17 00:00:00 2001 From: PuerNya Date: Sun, 24 Sep 2023 15:39:14 +0800 Subject: [PATCH] chore: handle provider proxies in proxies api --- hub/route/proxies.go | 4 ++-- tunnel/tunnel.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hub/route/proxies.go b/hub/route/proxies.go index 36c9d1b14..c1e30b219 100644 --- a/hub/route/proxies.go +++ b/hub/route/proxies.go @@ -46,7 +46,7 @@ func parseProxyName(next http.Handler) http.Handler { func findProxyByName(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { name := r.Context().Value(CtxKeyProxyName).(string) - proxies := tunnel.Proxies() + proxies := tunnel.ProxiesWithProviders() proxy, exist := proxies[name] if !exist { render.Status(r, http.StatusNotFound) @@ -60,7 +60,7 @@ func findProxyByName(next http.Handler) http.Handler { } func getProxies(w http.ResponseWriter, r *http.Request) { - proxies := tunnel.Proxies() + proxies := tunnel.ProxiesWithProviders() render.JSON(w, r, render.M{ "proxies": proxies, }) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index b7557e10b..fd601d30e 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -127,6 +127,20 @@ func Proxies() map[string]C.Proxy { return proxies } +func ProxiesWithProviders() map[string]C.Proxy { + allProxies := make(map[string]C.Proxy) + for name, proxy := range proxies { + allProxies[name] = proxy + } + for _, p := range providers { + for _, proxy := range p.Proxies() { + name := proxy.Name() + allProxies[name] = proxy + } + } + return allProxies +} + // Providers return all compatible providers func Providers() map[string]provider.ProxyProvider { return providers