Remove announce public

This commit is contained in:
Pablu23
2025-09-30 19:37:07 +02:00
parent 2d8323809a
commit 88fa68fa4c
4 changed files with 15 additions and 90 deletions

View File

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

View File

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

View File

@@ -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

View File

@@ -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")