Skip to content

Commit 940e19b

Browse files
committed
Fixes supabase-community#57 - Models throwing No Route errors when attempting to Update or Delete
1 parent 5c0c2ed commit 940e19b

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

Postgrest/Extensions/UriExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Postgrest.Extensions
66
{
77
public static class UriExtensions
88
{
9-
public static string GetBaseUrl(this Uri uri) =>
10-
uri.GetLeftPart(UriPartial.Authority);
9+
public static string GetInstanceUrl(this Uri uri) =>
10+
uri.GetLeftPart(UriPartial.Authority) + uri.LocalPath;
1111
}
1212
}

Postgrest/Responses/ModeledResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public ModeledResponse(BaseResponse baseResponse, JsonSerializerSettings seriali
4141
{
4242
foreach (var model in Models)
4343
{
44-
model.BaseUrl = baseResponse.ResponseMessage!.RequestMessage.RequestUri.GetBaseUrl();
44+
model.BaseUrl = baseResponse.ResponseMessage!.RequestMessage.RequestUri.GetInstanceUrl().Replace(model.TableName, "").TrimEnd('/');
4545
model.RequestClientOptions = ClientOptions;
4646
model.GetHeaders = getHeaders;
4747
}
@@ -55,7 +55,7 @@ public ModeledResponse(BaseResponse baseResponse, JsonSerializerSettings seriali
5555

5656
if (obj != null)
5757
{
58-
obj.BaseUrl = baseResponse.ResponseMessage!.RequestMessage.RequestUri.GetBaseUrl();
58+
obj.BaseUrl = baseResponse.ResponseMessage!.RequestMessage.RequestUri.GetInstanceUrl().Replace(obj.TableName, "").TrimEnd('/');
5959
obj.RequestClientOptions = ClientOptions;
6060
obj.GetHeaders = getHeaders;
6161

PostgrestTests/ClientApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void TestTableAttributeDefault()
5656
[TestMethod("will set header from options")]
5757
public void TestHeadersToken()
5858
{
59-
var headers = Helpers.PrepareRequestHeaders(HttpMethod.Get, new Dictionary<string, string> { { "Authorization", $"Bearer token" } });
59+
var headers = Postgrest.Helpers.PrepareRequestHeaders(HttpMethod.Get, new Dictionary<string, string> { { "Authorization", $"Bearer token" } });
6060

6161
Assert.AreEqual("Bearer token", headers["Authorization"]);
6262
}

PostgrestTests/Extensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ public class Extensions
1212
[TestMethod]
1313
public void UriExtensionGetBaseUri()
1414
{
15-
var uri1 = new Uri("https://abcdefg.supabase.io/testing/123?query=me-big-query");
15+
var uri1 = new Uri("https://abcdefg.supabase.io/rest/v1?query=me-big-query");
1616

17-
Assert.AreEqual("https://abcdefg.supabase.io", uri1.GetBaseUrl());
17+
Assert.AreEqual("https://abcdefg.supabase.io/rest/v1", uri1.GetInstanceUrl());
1818

1919
var uri2 = new Uri("http://localhost:3000/testing/123?query=me-big-query");
2020

21-
Assert.AreEqual("http://localhost:3000", uri2.GetBaseUrl());
21+
Assert.AreEqual("http://localhost:3000/testing/123", uri2.GetInstanceUrl());
2222
}
2323
}
2424
}

PostgrestTests/PostgrestTests.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
15-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
16-
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
17-
<PackageReference Include="coverlet.collector" Version="3.1.0">
14+
<PackageReference Include="gotrue-csharp" Version="3.0.4" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
16+
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
17+
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
18+
<PackageReference Include="coverlet.collector" Version="3.2.0">
1819
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1920
<PrivateAssets>all</PrivateAssets>
2021
</PackageReference>

0 commit comments

Comments
 (0)