Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ File: `ocap_recorder.cfg.json` (placed alongside DLL)
"logsDir": "./ocaplogs",
"defaultTag": "TvT",
"api": {
"serverUrl": "http://127.0.0.1:5000/api",
"serverUrl": "http://127.0.0.1:5000",
"apiKey": "secret"
},
"db": {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ocap_recorder/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"

"github.com/OCAP2/extension/v5/internal/api"
"github.com/OCAP2/extension/v5/internal/config"
"github.com/OCAP2/extension/v5/internal/storage"
"github.com/OCAP2/extension/v5/internal/storage/memory"
Expand Down Expand Up @@ -76,7 +77,7 @@ func createStorageBackend(storageCfg config.StorageConfig) (storage.Backend, err
return backend, nil

case "websocket":
wsURL := httpToWS(viper.GetString("api.serverUrl")) + "/v1/stream"
wsURL := httpToWS(viper.GetString("api.serverUrl")) + api.PathPrefix + "/v1/stream"
secret := viper.GetString("api.apiKey")
Logger.Info("WebSocket storage backend initialized", "url", wsURL)
return wsstorage.New(wsstorage.Config{
Expand Down
5 changes: 4 additions & 1 deletion internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"github.com/OCAP2/extension/v5/pkg/core"
)

// PathPrefix is the API path prefix appended to the base server URL.
const PathPrefix = "/api"

// Client handles communication with the OCAP web frontend.
type Client struct {
baseURL string
Expand All @@ -24,7 +27,7 @@ type Client struct {
// New creates a new API client.
func New(baseURL, apiKey string) *Client {
return &Client{
baseURL: strings.TrimRight(baseURL, "/"),
baseURL: strings.TrimRight(baseURL, "/") + PathPrefix,
apiKey: apiKey,
httpClient: &http.Client{Timeout: 30 * time.Second},
}
Expand Down
8 changes: 4 additions & 4 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ func TestNew(t *testing.T) {
c := New("http://localhost:5000", "secret123")

require.NotNil(t, c)
assert.Equal(t, "http://localhost:5000", c.baseURL)
assert.Equal(t, "http://localhost:5000/api", c.baseURL)
assert.Equal(t, "secret123", c.apiKey)
assert.NotNil(t, c.httpClient)
}

func TestNew_TrimsTrailingSlash(t *testing.T) {
c := New("http://localhost:5000/", "secret")
assert.Equal(t, "http://localhost:5000", c.baseURL)
assert.Equal(t, "http://localhost:5000/api", c.baseURL)
}

func TestHealthcheck_Success(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/healthcheck", r.URL.Path)
assert.Equal(t, "/api/healthcheck", r.URL.Path)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestUpload_Success(t *testing.T) {
var receivedFileContent []byte

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "/v1/operations/add", r.URL.Path)
assert.Equal(t, "/api/v1/operations/add", r.URL.Path)
assert.Equal(t, http.MethodPost, r.Method)

err := r.ParseMultipartForm(10 << 20)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Load(configDir string) error {
viper.SetDefault("defaultTag", "Op")
viper.SetDefault("logsDir", "./ocaplogs")

viper.SetDefault("api.serverUrl", "http://localhost:5000/api")
viper.SetDefault("api.serverUrl", "http://localhost:5000")
viper.SetDefault("api.apiKey", "")

viper.SetDefault("db.host", "localhost")
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestLoad_DefaultValues(t *testing.T) {
assert.Equal(t, "info", viper.GetString("logLevel"))
assert.Equal(t, "Op", viper.GetString("defaultTag"))
assert.Equal(t, "./ocaplogs", viper.GetString("logsDir"))
assert.Equal(t, "http://localhost:5000/api", viper.GetString("api.serverUrl"))
assert.Equal(t, "http://localhost:5000", viper.GetString("api.serverUrl"))
assert.Equal(t, "", viper.GetString("api.apiKey"))
assert.Equal(t, "localhost", viper.GetString("db.host"))
assert.Equal(t, "5432", viper.GetString("db.port"))
Expand Down
4 changes: 2 additions & 2 deletions ocap_recorder.cfg.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"logsDir": "./ocaplogs",
"defaultTag": "TvT",
"api": {
"serverUrl": "http://127.0.0.1:5000/api",
"serverUrl": "http://127.0.0.1:5000",
"apiKey": "same-secret"
},
"db": {
Expand All @@ -23,4 +23,4 @@
"dumpInterval": "3m"
}
}
}
}
Loading