url format improved

This commit is contained in:
mr 2024-10-07 15:07:06 +02:00
parent 03e066c297
commit 65668f5bee

View File

@ -32,14 +32,19 @@ type PeerCache struct {
func (p *PeerCache) urlFormat(url string, dt tools.DataType) string { func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
// localhost is replaced by the local peer URL // localhost is replaced by the local peer URL
// because localhost must collide on a web request security protocol // because localhost must collide on a web request security protocol
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") { localhost := ""
r := regexp.MustCompile("(:[0-9]+)") if strings.Contains(url, "localhost") {
localhost = "localhost"
}
if strings.Contains(url, "127.0.0.1") {
localhost = "127.0.0.1"
}
if localhost != "" {
r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
t := r.FindString(url) t := r.FindString(url)
if t != "" { if t != "" {
url = strings.Replace(url, t, "", -1) url = strings.Replace(url, t, dt.API()+":8080", -1)
} }
url = strings.ReplaceAll(url, "localhost", dt.API()+":8080")
url = strings.ReplaceAll(url, "127.0.0.1", dt.API()+":8080")
} else { } else {
url = url + "/" + dt.API() url = url + "/" + dt.API()
} }