diff --git a/server/server.go b/server/server.go index 424d548..13e9c82 100755 --- a/server/server.go +++ b/server/server.go @@ -201,7 +201,22 @@ func pushMeta(r *http.Request, k, v string) { } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { - s.Pre(s.Proxy)(w, r) + foo := s.Proxy + if strings.Split(r.Host, ".")[0] == "_" { + keys := s.db.Keys(nsRouting) + hostURL := map[string]string{} + for _, key := range keys { + u, _ := s.lookup(key) + if u != nil { + hostURL[key] = u.String() + } + } + json.NewEncoder(w).Encode(map[string]any{ + "hostsToURLs": hostURL, + }) + return + } + s.Pre(foo)(w, r) } type corsResponseWriter struct { diff --git a/storage/db.go b/storage/db.go index 20c0140..8481217 100755 --- a/storage/db.go +++ b/storage/db.go @@ -2,6 +2,7 @@ package storage import ( "errors" + "gitea.inhome.blapointe.com/local/rproxy3/storage/packable" ) @@ -10,5 +11,6 @@ var ErrNotFound = errors.New("not found") type DB interface { Get(string, string, packable.Packable) error Set(string, string, packable.Packable) error + Keys(string) []string Close() error } diff --git a/storage/map.go b/storage/map.go index bf78cc5..f2fa458 100755 --- a/storage/map.go +++ b/storage/map.go @@ -2,6 +2,7 @@ package storage import ( "fmt" + "gitea.inhome.blapointe.com/local/rproxy3/storage/packable" ) @@ -40,6 +41,15 @@ func (m Map) Close() error { return nil } +func (m Map) Keys(ns string) []string { + m2, _ := m[ns] + result := make([]string, 0, len(m2)) + for k := range m2 { + result = append(result, k) + } + return result +} + func (m Map) Get(ns, key string, value packable.Packable) error { if _, ok := m[ns]; !ok { m[ns] = make(map[string][]byte)