update getting hostname logic

This commit is contained in:
Lakhan Samani
2021-07-22 05:22:53 +05:30
parent caf0b24b0c
commit d65edcc47a
2 changed files with 24 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
package utils
import (
"log"
"net/url"
"strings"
"github.com/yauthdev/yauth/server/constants"
)
@@ -13,7 +13,25 @@ func GetFrontendHost() string {
return `localhost`
}
log.Println("hostname", "."+u.Hostname())
host := u.Hostname()
hostParts := strings.Split(host, ".")
hostPartsLen := len(hostParts)
return "." + u.Hostname()
if hostPartsLen == 1 {
return host
}
if hostPartsLen == 2 {
if hostParts[0] == "www" {
return hostParts[1]
} else {
return host
}
}
if hostPartsLen > 2 {
return strings.Join(hostParts[hostPartsLen-2:], ".")
}
return host
}