fix: add valid origin check for cors (#83)

Resolves #72
This commit is contained in:
Lakhan Samani
2021-12-21 18:46:54 +05:30
committed by GitHub
parent bdbbe4adee
commit 8f7582e1ec
12 changed files with 180 additions and 59 deletions

View File

@@ -5,21 +5,32 @@ import (
"strings"
)
// GetHostName function to get hostname
func GetHostName(auth_url string) string {
u, err := url.Parse(auth_url)
// GetHostName function returns hostname and port
func GetHostParts(uri string) (string, string) {
tempURI := uri
if !strings.HasPrefix(tempURI, "http") && strings.HasPrefix(tempURI, "https") {
tempURI = "https://" + tempURI
}
u, err := url.Parse(tempURI)
if err != nil {
return `localhost`
return "localhost", "8080"
}
host := u.Hostname()
port := u.Port()
return host
return host, port
}
// GetDomainName function to get domain name
func GetDomainName(auth_url string) string {
u, err := url.Parse(auth_url)
func GetDomainName(uri string) string {
tempURI := uri
if !strings.HasPrefix(tempURI, "http") && strings.HasPrefix(tempURI, "https") {
tempURI = "https://" + tempURI
}
u, err := url.Parse(tempURI)
if err != nil {
return `localhost`
}