master
bel 2025-06-19 16:49:06 -06:00
parent e4451923e9
commit 5a0f567da3
3 changed files with 28 additions and 1 deletions

View File

@ -201,7 +201,22 @@ 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) {
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 { type corsResponseWriter struct {

View File

@ -2,6 +2,7 @@ package storage
import ( import (
"errors" "errors"
"gitea.inhome.blapointe.com/local/rproxy3/storage/packable" "gitea.inhome.blapointe.com/local/rproxy3/storage/packable"
) )
@ -10,5 +11,6 @@ var ErrNotFound = errors.New("not found")
type DB interface { type DB interface {
Get(string, string, packable.Packable) error Get(string, string, packable.Packable) error
Set(string, string, packable.Packable) error Set(string, string, packable.Packable) error
Keys(string) []string
Close() error Close() error
} }

View File

@ -2,6 +2,7 @@ package storage
import ( import (
"fmt" "fmt"
"gitea.inhome.blapointe.com/local/rproxy3/storage/packable" "gitea.inhome.blapointe.com/local/rproxy3/storage/packable"
) )
@ -40,6 +41,15 @@ func (m Map) Close() error {
return nil 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 { func (m Map) Get(ns, key string, value packable.Packable) error {
if _, ok := m[ns]; !ok { if _, ok := m[ns]; !ok {
m[ns] = make(map[string][]byte) m[ns] = make(map[string][]byte)