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,8 +206,10 @@ 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] == "_" { }
func (s *Server) List(w http.ResponseWriter) {
keys := s.db.Keys(nsRouting) keys := s.db.Keys(nsRouting)
hostURL := map[string]string{} hostURL := map[string]string{}
for _, key := range keys { for _, key := range keys {
@ -214,9 +221,6 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]any{ json.NewEncoder(w).Encode(map[string]any{
"hostsToURLs": hostURL, "hostsToURLs": hostURL,
}) })
return
}
s.Pre(foo)(w, r)
} }
type corsResponseWriter struct { type corsResponseWriter struct {