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(
35
35
. product( name: " PostgREST " , package : " postgrest-swift " ) ,
36
36
. product( name: " Functions " , package : " functions-swift " ) ,
37
37
]
38
- )
38
+ ) ,
39
+ . testTarget( name: " SupabaseTests " , dependencies: [ " Supabase " ] ) ,
39
40
]
40
41
)
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ public class SupabaseClient {
12
12
private let supabaseKey : String
13
13
private let schema : String
14
14
15
+ let functionsURL : URL
16
+
15
17
/// Supabase Auth allows you to create and manage user sessions for access to data that is secured
16
18
/// by access policies.
17
19
public let auth : GoTrueClient
@@ -46,7 +48,7 @@ public class SupabaseClient {
46
48
/// Supabase Functions allows you to deploy and invoke edge functions.
47
49
public var functions : FunctionsClient {
48
50
FunctionsClient (
49
- url: supabaseURL . appendingPathComponent ( " /functions/v1 " ) ,
51
+ url: functionsURL ,
50
52
headers: defaultHeaders,
51
53
apiClientDelegate: self
52
54
)
@@ -81,6 +83,16 @@ public class SupabaseClient {
81
83
url: supabaseURL. appendingPathComponent ( " /auth/v1 " ) ,
82
84
headers: defaultHeaders
83
85
)
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
+ }
84
96
}
85
97
86
98
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