From 88fa68fa4cd5f8503f4768bccb075995847b186a Mon Sep 17 00:00:00 2001 From: Pablu23 Date: Tue, 30 Sep 2025 19:37:07 +0200 Subject: [PATCH] Remove announce public --- cmd/domain-router/main.go | 10 ------- config.go | 5 ---- config.yaml | 30 ++++++++------------ router.go | 60 ++------------------------------------- 4 files changed, 15 insertions(+), 90 deletions(-) diff --git a/cmd/domain-router/main.go b/cmd/domain-router/main.go index 5f1b96c..ee2c173 100644 --- a/cmd/domain-router/main.go +++ b/cmd/domain-router/main.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "net/http" - "net/url" "os" "time" @@ -42,15 +41,6 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", router.ServeHTTP) - if config.General.AnnouncePublic { - h, err := url.JoinPath("/", config.General.HealthEndpoint) - if err != nil { - log.Error().Err(err).Str("endpoint", config.General.HealthEndpoint).Msg("Could not create endpoint path") - h = "/healthz" - } - mux.HandleFunc(h, router.Healthz) - } - pipeline := configureMiddleware(config) server := http.Server{ diff --git a/config.go b/config.go index 6b11f4e..71ea914 100644 --- a/config.go +++ b/config.go @@ -1,10 +1,6 @@ package domainrouter type Config struct { - General struct { - AnnouncePublic bool `yaml:"announce"` - HealthEndpoint string `yaml:"healthz"` - } `yaml:"general"` Server struct { Port int `yaml:"port"` Ssl struct { @@ -26,7 +22,6 @@ type Config struct { Port int `yaml:"port"` Remotes []string `yaml:"remotes"` Domains []string `yaml:"domains"` - Public bool `yaml:"public"` Secure bool `yaml:"secure"` } `yaml:"hosts"` RateLimit struct { diff --git a/config.yaml b/config.yaml index c4fe7f1..b9a875a 100644 --- a/config.yaml +++ b/config.yaml @@ -46,8 +46,6 @@ hosts: - localhost # Port on which to request port: 8181 - # Health check if announce is true - public: true # Domains which get redirected to host domains: - localhost @@ -56,30 +54,26 @@ hosts: - remotes: - localhost port: 8282 - public: false domains: - private.localhost - remotes: - localhost port: 5173 - public: false domains: - hitstar.localhost - hipstar.localhost - # - remotes: - # - www.google.com - # - localhost - # port: 443 - # public: false - # # Uses https under the hood to communicate with the remote host - # secure: true - # domains: - # - google.localhost + - remotes: + - 127.0.0.1 + port: 46009 + domains: + - chat.localhost -general: - # Expose health endpoint, that requests health endpoints from hosts which are public - announce: true - # Path to health endpoint on router, is allowed to conflict with hosts, but overwrites specific host endpoint - healthz: healthz + - remotes: + - www.google.com + port: 443 + # Uses https under the hood to communicate with the remote host + secure: true + domains: + - google.localhost diff --git a/router.go b/router.go index 525d44b..daeb3d5 100644 --- a/router.go +++ b/router.go @@ -2,7 +2,6 @@ package domainrouter import ( "context" - "encoding/json" "errors" "fmt" "io" @@ -53,61 +52,7 @@ func (router *Router) roundRobin(host *Host) { } } -func (router *Router) Healthz(w http.ResponseWriter, r *http.Request) { - if !router.config.General.AnnouncePublic { - http.NotFound(w, r) - return - } - - result := make([]struct { - Domain string - Healthy bool - }, 0) - - for _, host := range router.config.Hosts { - if !host.Public { - continue - } - - healthy := true - for _, remote := range host.Remotes { - var url string - if host.Secure { - url = fmt.Sprintf("https://%s:%d/healthz", remote, host.Port) - } else { - url = fmt.Sprintf("http://%s:%d/healthz", remote, host.Port) - } - - res, err := router.client.Get(url) - if err != nil { - log.Warn().Err(err).Str("remote", remote).Int("port", host.Port).Msg("Unhealthy") - healthy = false - } else if res.StatusCode != 200 { - healthy = false - } - } - - for _, domain := range host.Domains { - result = append(result, struct { - Domain string - Healthy bool - }{domain, healthy}) - } - } - - data, err := json.Marshal(&result) - if err != nil { - log.Error().Err(err).Msg("Could not json encode Healthz") - w.WriteHeader(http.StatusInternalServerError) - return - } - - w.Header().Add("Content-Type", "application/json") - w.Write(data) - w.WriteHeader(http.StatusOK) -} - -func rewriteRequestURL(r *http.Request, host *Host, remote string) error { +func rewriteRequestURL(r *http.Request, host *Host, remote string, ) error { subUrlPath := r.URL.RequestURI() var uri string if host.Secure { @@ -172,6 +117,7 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) { if reqUpType != "" { outreq.Header.Set("Connection", "Upgrade") outreq.Header.Set("Upgrade", reqUpType) + log.Debug().Str("upgrade", reqUpType).Msg("Request upgrade") } stripClientProvidedXForwardHeaders(outreq.Header) @@ -379,7 +325,7 @@ func upgradeType(header http.Header) string { } func dumpRequest(w http.ResponseWriter, r *http.Request) bool { - if e := log.Trace(); e.Enabled() && r.Method == "POST" { + if e := log.Trace(); e.Enabled() { rDump, err := httputil.DumpRequest(r, true) if err != nil { log.Error().Err(err).Msg("Could not dump request")