diff --git a/server/server.go b/server/server.go index 2121b13..fcfb81a 100755 --- a/server/server.go +++ b/server/server.go @@ -154,6 +154,11 @@ func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc { return } + if mapKey(r.Host) == "_" { + s.List(w) + return + } + if auth, err := s.lookupAuth(mapKey(r.Host)); err != nil { log.Printf("failed to lookup auth for %s (%s): %v", r.Host, mapKey(r.Host), err) w.Header().Set("WWW-Authenticate", "Basic") @@ -201,22 +206,21 @@ func pushMeta(r *http.Request, k, v string) { } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { - foo := s.Proxy - if strings.Split(r.URL.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() - } + s.Pre(s.Proxy)(w, r) +} + +func (s *Server) List(w http.ResponseWriter) { + 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) + json.NewEncoder(w).Encode(map[string]any{ + "hostsToURLs": hostURL, + }) } type corsResponseWriter struct {