Make service endpoint more robust
Change-Id: I7e4048a95f8e9c3837d4831213a1f454c9c20cd4
diff --git a/cmd/termmapper/main.go b/cmd/termmapper/main.go
index 644fa06..4c868b5 100644
--- a/cmd/termmapper/main.go
+++ b/cmd/termmapper/main.go
@@ -2,8 +2,10 @@
import (
"fmt"
+ "net/url"
"os"
"os/signal"
+ "path"
"path/filepath"
"strings"
"syscall"
@@ -350,12 +352,21 @@
</dl>`
if data.MapID != "" {
+
+ serviceURL, err := url.Parse(data.ServiceURL)
+ if err != nil {
+ log.Warn().Err(err).Msg("Failed to join URL path")
+ }
+
+ // Use path.Join to normalize the path part
+ serviceURL.Path = path.Join(serviceURL.Path, data.MapID+"/query")
+
html += ` <script>
<!-- activates/deactivates Mapper. -->
let data = {
'action' : 'pipe',
- 'service' : '` + data.ServiceURL + `/` + data.MapID + `/query'
+ 'service' : '` + serviceURL.String() + `'
};
function pluginit (p) {