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
}
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 {