From 56ccdfbdb2821ccf99dcf74b2094bc409bb66ff8 Mon Sep 17 00:00:00 2001 From: Sam Lewis Date: Sun, 19 Jan 2025 20:58:16 -0500 Subject: [PATCH] two url fixes: - default scheme for legacy connection params - set paths for http and websocket APIs --- app.go | 4 ++++ internal/http/http.go | 1 + internal/websocket/websocket.go | 1 + 3 files changed, 6 insertions(+) diff --git a/app.go b/app.go index 66cf94f..bd20a4f 100644 --- a/app.go +++ b/app.go @@ -109,6 +109,10 @@ func NewApp(request NewAppRequest) (*App, error) { if port == "" { port = "8123" } + baseURL.Scheme = "http" + if request.Secure { + baseURL.Scheme = "https" + } baseURL.Host = request.IpAddress + ":" + port } diff --git a/internal/http/http.go b/internal/http/http.go index 8fee706..8d9c9f7 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -18,6 +18,7 @@ type HttpClient struct { func NewHttpClient(url *url.URL, token string) *HttpClient { // Shallow copy the URL to avoid modifying the original u := *url + u.Path = "/api" if u.Scheme == "ws" { u.Scheme = "http" } diff --git a/internal/websocket/websocket.go b/internal/websocket/websocket.go index ad48b33..eab5030 100644 --- a/internal/websocket/websocket.go +++ b/internal/websocket/websocket.go @@ -51,6 +51,7 @@ func ConnectionFromUri(baseURL *url.URL, authToken string) (*websocket.Conn, con // Shallow copy the URL to avoid modifying the original urlWebsockets := *baseURL + urlWebsockets.Path = "/api/websocket" if baseURL.Scheme == "http" { urlWebsockets.Scheme = "ws" }