chore: handle provider proxies in proxies api
This commit is contained in:
parent
89d8589654
commit
5cae2e157b
2 changed files with 16 additions and 2 deletions
|
@ -46,7 +46,7 @@ func parseProxyName(next http.Handler) http.Handler {
|
||||||
func findProxyByName(next http.Handler) http.Handler {
|
func findProxyByName(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
name := r.Context().Value(CtxKeyProxyName).(string)
|
name := r.Context().Value(CtxKeyProxyName).(string)
|
||||||
proxies := tunnel.Proxies()
|
proxies := tunnel.ProxiesWithProviders()
|
||||||
proxy, exist := proxies[name]
|
proxy, exist := proxies[name]
|
||||||
if !exist {
|
if !exist {
|
||||||
render.Status(r, http.StatusNotFound)
|
render.Status(r, http.StatusNotFound)
|
||||||
|
@ -60,7 +60,7 @@ func findProxyByName(next http.Handler) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProxies(w http.ResponseWriter, r *http.Request) {
|
func getProxies(w http.ResponseWriter, r *http.Request) {
|
||||||
proxies := tunnel.Proxies()
|
proxies := tunnel.ProxiesWithProviders()
|
||||||
render.JSON(w, r, render.M{
|
render.JSON(w, r, render.M{
|
||||||
"proxies": proxies,
|
"proxies": proxies,
|
||||||
})
|
})
|
||||||
|
|
|
@ -127,6 +127,20 @@ func Proxies() map[string]C.Proxy {
|
||||||
return proxies
|
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
|
// Providers return all compatible providers
|
||||||
func Providers() map[string]provider.ProxyProvider {
|
func Providers() map[string]provider.ProxyProvider {
|
||||||
return providers
|
return providers
|
||||||
|
|
Loading…
Reference in a new issue