fixed subdomain matching for sub-sub-subdomain and so on, now return 404 when subdomain is missing

This commit is contained in:
yusing 2024-09-24 18:30:25 +08:00
parent f426dbc9cf
commit 99216ffe59

View file

@ -148,7 +148,12 @@ func ProxyHandler(w http.ResponseWriter, r *http.Request) {
}
func findMux(host string) (*http.ServeMux, E.NestedError) {
sd := strings.Split(host, ".")[0]
hostSplit := strings.Split(host, ".")
n := len(hostSplit)
if n <= 2 {
return nil, E.Missing("subdomain")
}
sd := strings.Join(hostSplit[:n-2], ".")
if r, ok := httpRoutes.Load(PT.Alias(sd)); ok {
return r.mux, nil
}