2021-07-14 18:43:19 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
2021-07-21 23:52:53 +00:00
|
|
|
"strings"
|
2021-07-14 18:43:19 +00:00
|
|
|
|
|
|
|
"github.com/yauthdev/yauth/server/constants"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetFrontendHost() string {
|
|
|
|
u, err := url.Parse(constants.FRONTEND_URL)
|
|
|
|
if err != nil {
|
|
|
|
return `localhost`
|
|
|
|
}
|
|
|
|
|
2021-07-21 23:52:53 +00:00
|
|
|
host := u.Hostname()
|
|
|
|
hostParts := strings.Split(host, ".")
|
|
|
|
hostPartsLen := len(hostParts)
|
2021-07-21 15:57:12 +00:00
|
|
|
|
2021-07-21 23:52:53 +00:00
|
|
|
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
|
2021-07-14 18:43:19 +00:00
|
|
|
}
|