|
@@ -143,7 +143,6 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
|
|
|
|
|
|
if h.Parent.RootRoutingOptions.EnableRedirectForUnsetRules {
|
|
|
//Route to custom domain
|
|
|
- fmt.Println("test1", h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget)
|
|
|
if h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget == "" {
|
|
|
//Not set. Redirect to first level of domain redirectable
|
|
|
fld, err := h.getTopLevelRedirectableDomain(domainOnly)
|
|
@@ -208,9 +207,22 @@ func (h *ProxyHandler) handleAccessRouting(w http.ResponseWriter, r *http.Reques
|
|
|
// that is redirectable. E.g. a.b.c.example.co.uk will return example.co.uk
|
|
|
func (h *ProxyHandler) getTopLevelRedirectableDomain(unsetSubdomainHost string) (string, error) {
|
|
|
parts := strings.Split(unsetSubdomainHost, ".")
|
|
|
- if len(parts) > 1 {
|
|
|
- newDomain := strings.Join(parts[1:], ".")
|
|
|
- return "//" + newDomain, nil
|
|
|
+ fmt.Println(parts)
|
|
|
+ if len(parts) <= 2 {
|
|
|
+ //Already topped
|
|
|
+ return "", errors.New("already at top level domain")
|
|
|
+ }
|
|
|
+
|
|
|
+ for i := 0; i < len(parts); i++ {
|
|
|
+ possibleTld := parts[i:]
|
|
|
+ fmt.Println(possibleTld)
|
|
|
+ _, ok := h.Parent.tldMap[strings.Join(possibleTld, ".")]
|
|
|
+ if ok {
|
|
|
+ //This is tld length
|
|
|
+ tld := strings.Join(parts[i-1:], ".")
|
|
|
+ fmt.Println("Redirecting to: //" + tld)
|
|
|
+ return "//" + tld, nil
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return "", errors.New("unsupported top level domain given")
|