File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ let package = Package(
3535 . product( name: " PostgREST " , package : " postgrest-swift " ) ,
3636 . product( name: " Functions " , package : " functions-swift " ) ,
3737 ]
38- )
38+ ) ,
39+ . testTarget( name: " SupabaseTests " , dependencies: [ " Supabase " ] ) ,
3940 ]
4041)
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ public class SupabaseClient {
1212 private let supabaseKey : String
1313 private let schema : String
1414
15+ let functionsURL : URL
16+
1517 /// Supabase Auth allows you to create and manage user sessions for access to data that is secured
1618 /// by access policies.
1719 public let auth : GoTrueClient
@@ -46,7 +48,7 @@ public class SupabaseClient {
4648 /// Supabase Functions allows you to deploy and invoke edge functions.
4749 public var functions : FunctionsClient {
4850 FunctionsClient (
49- url: supabaseURL . appendingPathComponent ( " /functions/v1 " ) ,
51+ url: functionsURL ,
5052 headers: defaultHeaders,
5153 apiClientDelegate: self
5254 )
@@ -81,6 +83,16 @@ public class SupabaseClient {
8183 url: supabaseURL. appendingPathComponent ( " /auth/v1 " ) ,
8284 headers: defaultHeaders
8385 )
86+
87+ let isPlatform =
88+ supabaseURL. absoluteString. contains ( " supabase.co " )
89+ || supabaseURL. absoluteString. contains ( " supabase.in " )
90+ if isPlatform {
91+ let urlParts = supabaseURL. absoluteString. split ( separator: " . " )
92+ functionsURL = URL ( string: " \( urlParts [ 0 ] ) .functions. \( urlParts [ 1 ] ) . \( urlParts [ 2 ] ) " ) !
93+ } else {
94+ functionsURL = supabaseURL. appendingPathComponent ( " functions/v1 " )
95+ }
8496 }
8597
8698 public struct HTTPClient {
Original file line number Diff line number Diff line change 1+ import XCTest
2+ @testable import Supabase
3+
4+ final class SupabaseClientTests : XCTestCase {
5+ func testFunctionsURL( ) {
6+ var client = SupabaseClient ( supabaseURL: URL ( string: " https://project-ref.supabase.co " ) !, supabaseKey: " ANON_KEY " )
7+ XCTAssertEqual ( client. functionsURL. absoluteString, " https://project-ref.functions.supabase.co " )
8+
9+ client = SupabaseClient ( supabaseURL: URL ( string: " https://project-ref.supabase.in " ) !, supabaseKey: " ANON_KEY " )
10+ XCTAssertEqual ( client. functionsURL. absoluteString, " https://project-ref.functions.supabase.in " )
11+
12+ client = SupabaseClient ( supabaseURL: URL ( string: " https://custom-domain.com " ) !, supabaseKey: " ANON_KEY " )
13+ XCTAssertEqual ( client. functionsURL. absoluteString, " https://custom-domain.com/functions/v1 " )
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments