update getting hostname logic
This commit is contained in:
parent
caf0b24b0c
commit
d65edcc47a
|
@ -14,10 +14,11 @@ func SetCookie(gc *gin.Context, token string) {
|
|||
if !constants.IS_PROD {
|
||||
secure = false
|
||||
}
|
||||
|
||||
host := GetFrontendHost()
|
||||
log.Println("-> is cookie secure", secure)
|
||||
log.Println("-> host:", host)
|
||||
|
||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", GetFrontendHost(), secure, httpOnly)
|
||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
||||
}
|
||||
|
||||
func DeleteCookie(gc *gin.Context) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user