Skip to content

Commit e5101d4

Browse files
authored
elixir-client: Revert change to way base_url is used (#1998)
Originally the /v1/shape path was appended onto the `base_url` path, but #1994 changed that to ignore any path elements in the base_url. This change un-does that and reverts back to appending the /v1/shape path onto the base_url. (no changeset included as the one in #1994 covers this) @msfstef almost backwards compatible...
1 parent 1ef34ab commit e5101d4

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/elixir-client/lib/electric/client.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ defmodule Electric.Client do
218218
If you configure your client using e.g. `base_url: "http://localhost:3000"`
219219
Electric will append the default shape API path
220220
`#{inspect(@api_endpoint_path)}` to create the final endpoint configuration,
221-
in this case `"http://localhost:3000#{@api_endpoint_path}"`. Note that any
222-
trailing path in the `base_url` is ignored.
221+
in this case `"http://localhost:3000#{@api_endpoint_path}"`.
223222
224223
If you wish to use a non-standard endpoint path because, for example, you wrap your Shape
225224
API calls in an [authentication
@@ -246,7 +245,7 @@ defmodule Electric.Client do
246245
case Map.fetch(attrs, :base_url) do
247246
{:ok, url} ->
248247
with {:ok, uri} <- URI.new(url) do
249-
{:ok, %{uri | path: @api_endpoint_path}}
248+
{:ok, URI.append_path(uri, @api_endpoint_path)}
250249
end
251250

252251
:error ->

packages/elixir-client/test/electric/client_test.exs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ defmodule Electric.ClientTest do
3636
end
3737

3838
describe "new" do
39-
test ":url is used as the base of the endpoint" do
39+
test ":base_url is used as the base of the endpoint" do
4040
endpoint = URI.new!("http://localhost:3000/v1/shape")
4141

4242
{:ok, %Client{endpoint: ^endpoint}} =
4343
Client.new(base_url: "http://localhost:3000")
4444

45+
endpoint = URI.new!("http://localhost:3000/proxy/v1/shape")
46+
4547
{:ok, %Client{endpoint: ^endpoint}} =
46-
Client.new(base_url: "http://localhost:3000/v1/shape")
48+
Client.new(base_url: "http://localhost:3000/proxy")
49+
50+
endpoint = URI.new!("http://localhost:3000/some/random/path/v1/shape")
4751

4852
{:ok, %Client{endpoint: ^endpoint}} =
4953
Client.new(base_url: "http://localhost:3000/some/random/path")

0 commit comments

Comments
 (0)