master
bel 2025-06-19 16:56:52 -06:00
parent 00eda1e419
commit 8d018aa236
1 changed files with 18 additions and 14 deletions

View File

@ -154,6 +154,11 @@ func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
return return
} }
if mapKey(r.Host) == "_" {
s.List(w)
return
}
if auth, err := s.lookupAuth(mapKey(r.Host)); err != nil { 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) log.Printf("failed to lookup auth for %s (%s): %v", r.Host, mapKey(r.Host), err)
w.Header().Set("WWW-Authenticate", "Basic") 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) { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
foo := s.Proxy s.Pre(s.Proxy)(w, r)
if strings.Split(r.URL.Host, ".")[0] == "_" { }
keys := s.db.Keys(nsRouting)
hostURL := map[string]string{} func (s *Server) List(w http.ResponseWriter) {
for _, key := range keys { keys := s.db.Keys(nsRouting)
u, _ := s.lookup(key) hostURL := map[string]string{}
if u != nil { for _, key := range keys {
hostURL[key] = u.String() 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 { type corsResponseWriter struct {