From 65668f5beee10ebf8ab066edd8893945a0e682e0 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 7 Oct 2024 15:07:06 +0200 Subject: [PATCH] url format improved --- models/peer/peer_cache.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/models/peer/peer_cache.go b/models/peer/peer_cache.go index 516ab20..1cbb84c 100644 --- a/models/peer/peer_cache.go +++ b/models/peer/peer_cache.go @@ -32,14 +32,19 @@ type PeerCache struct { func (p *PeerCache) urlFormat(url string, dt tools.DataType) string { // localhost is replaced by the local peer URL // because localhost must collide on a web request security protocol - if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") { - r := regexp.MustCompile("(:[0-9]+)") + localhost := "" + 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) 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 { url = url + "/" + dt.API() }