Fix bmx base url

This commit is contained in:
Tobias Gesellchen
2026-02-26 21:08:14 +01:00
parent b4c015ef75
commit 2132674768
3 changed files with 31 additions and 6 deletions
+1 -5
View File
@@ -4,7 +4,6 @@ package handlers
import (
"encoding/json"
"net/http"
"os"
"strings"
"github.com/gesellix/bose-soundtouch/pkg/service/bmx"
@@ -13,10 +12,7 @@ import (
// HandleBMXRegistry returns the BMX service registry.
func (s *Server) HandleBMXRegistry(w http.ResponseWriter, _ *http.Request) {
baseURL := os.Getenv("BASE_URL")
if baseURL == "" {
baseURL = "http://localhost:8000"
}
baseURL := s.serverURL
content := string(bmxServicesJSON)
content = strings.ReplaceAll(content, "{BMX_SERVER}", baseURL)
+29
View File
@@ -39,6 +39,10 @@ func TestBMXServices(t *testing.T) {
// Verify placeholder replacement
bodyStr := string(body)
if !strings.Contains(bodyStr, "http://localhost:8001") {
t.Errorf("Response does not contain expected baseURL http://localhost:8001, got: %s", bodyStr)
}
if strings.Contains(bodyStr, "{BMX_SERVER}") {
t.Error("Response still contains {BMX_SERVER} placeholder")
}
@@ -48,6 +52,31 @@ func TestBMXServices(t *testing.T) {
}
}
func TestBMXServices_EmptyBaseURL(t *testing.T) {
r, _ := setupRouter("", nil)
ts := httptest.NewServer(r)
defer ts.Close()
res, err := http.Get(ts.URL + "/bmx/registry/v1/services")
if err != nil {
t.Fatal(err)
}
defer func() { _ = res.Body.Close() }()
body, _ := io.ReadAll(res.Body)
bodyStr := string(body)
// Since we removed the fallback, it should use the empty baseURL
if strings.Contains(bodyStr, "http://localhost:8000") {
t.Error("Response contains fallback URL http://localhost:8000, which should be removed")
}
if strings.Contains(bodyStr, "{BMX_SERVER}") {
t.Error("Response still contains {BMX_SERVER} placeholder")
}
}
func TestOrionPlayback(t *testing.T) {
r, _ := setupRouter("http://localhost:8001", nil)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
)
func setupRouter(targetURL string, ds *datastore.DataStore) (*chi.Mux, *Server) {
server := NewServer(ds, nil, "http://localhost:8000", false, false, false, false, false, false)
server := NewServer(ds, nil, targetURL, false, false, false, false, false, false)
server.SetSoundcorkURL(targetURL)
r := chi.NewRouter()