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" "fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"os" "os"
"time" "time"
@@ -42,15 +41,6 @@ func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/", router.ServeHTTP) 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) pipeline := configureMiddleware(config)
server := http.Server{ server := http.Server{

View File

@@ -1,10 +1,6 @@
package domainrouter package domainrouter
type Config struct { type Config struct {
General struct {
AnnouncePublic bool `yaml:"announce"`
HealthEndpoint string `yaml:"healthz"`
} `yaml:"general"`
Server struct { Server struct {
Port int `yaml:"port"` Port int `yaml:"port"`
Ssl struct { Ssl struct {
@@ -26,7 +22,6 @@ type Config struct {
Port int `yaml:"port"` Port int `yaml:"port"`
Remotes []string `yaml:"remotes"` Remotes []string `yaml:"remotes"`
Domains []string `yaml:"domains"` Domains []string `yaml:"domains"`
Public bool `yaml:"public"`
Secure bool `yaml:"secure"` Secure bool `yaml:"secure"`
} `yaml:"hosts"` } `yaml:"hosts"`
RateLimit struct { RateLimit struct {

View File

@@ -46,8 +46,6 @@ hosts:
- localhost - localhost
# Port on which to request # Port on which to request
port: 8181 port: 8181
# Health check if announce is true
public: true
# Domains which get redirected to host # Domains which get redirected to host
domains: domains:
- localhost - localhost
@@ -56,30 +54,26 @@ hosts:
- remotes: - remotes:
- localhost - localhost
port: 8282 port: 8282
public: false
domains: domains:
- private.localhost - private.localhost
- remotes: - remotes:
- localhost - localhost
port: 5173 port: 5173
public: false
domains: domains:
- hitstar.localhost - hitstar.localhost
- hipstar.localhost - hipstar.localhost
# - remotes: - remotes:
# - www.google.com - 127.0.0.1
# - localhost port: 46009
# port: 443 domains:
# public: false - chat.localhost
# # Uses https under the hood to communicate with the remote host
# secure: true
# domains:
# - google.localhost
general: - remotes:
# Expose health endpoint, that requests health endpoints from hosts which are public - www.google.com
announce: true port: 443
# Path to health endpoint on router, is allowed to conflict with hosts, but overwrites specific host endpoint # Uses https under the hood to communicate with the remote host
healthz: healthz secure: true
domains:
- google.localhost

View File

@@ -2,7 +2,6 @@ package domainrouter
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@@ -53,61 +52,7 @@ func (router *Router) roundRobin(host *Host) {
} }
} }
func (router *Router) Healthz(w http.ResponseWriter, r *http.Request) { func rewriteRequestURL(r *http.Request, host *Host, remote string, ) error {
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 {
subUrlPath := r.URL.RequestURI() subUrlPath := r.URL.RequestURI()
var uri string var uri string
if host.Secure { if host.Secure {
@@ -172,6 +117,7 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if reqUpType != "" { if reqUpType != "" {
outreq.Header.Set("Connection", "Upgrade") outreq.Header.Set("Connection", "Upgrade")
outreq.Header.Set("Upgrade", reqUpType) outreq.Header.Set("Upgrade", reqUpType)
log.Debug().Str("upgrade", reqUpType).Msg("Request upgrade")
} }
stripClientProvidedXForwardHeaders(outreq.Header) stripClientProvidedXForwardHeaders(outreq.Header)
@@ -379,7 +325,7 @@ func upgradeType(header http.Header) string {
} }
func dumpRequest(w http.ResponseWriter, r *http.Request) bool { 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) rDump, err := httputil.DumpRequest(r, true)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Could not dump request") log.Error().Err(err).Msg("Could not dump request")