File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ export default class SupabaseClient<
84
84
85
85
const _supabaseUrl = stripTrailingSlash ( supabaseUrl )
86
86
87
- this . realtimeUrl = `${ _supabaseUrl } /realtime/v1` . replace ( ' http' , 'ws' )
87
+ this . realtimeUrl = `${ _supabaseUrl } /realtime/v1` . replace ( / ^ h t t p / i , 'ws' )
88
88
this . authUrl = `${ _supabaseUrl } /auth/v1`
89
89
this . storageUrl = `${ _supabaseUrl } /storage/v1`
90
90
Original file line number Diff line number Diff line change @@ -28,6 +28,35 @@ describe('Custom Headers', () => {
28
28
} )
29
29
} )
30
30
31
+ describe ( 'Realtime url' , ( ) => {
32
+ test ( 'should switch protocol from http to ws' , ( ) => {
33
+ const client = createClient ( 'http://localhost:3000' , KEY )
34
+
35
+ // @ts -ignore
36
+ const realtimeUrl = client . realtimeUrl
37
+
38
+ expect ( realtimeUrl ) . toEqual ( 'ws://localhost:3000/realtime/v1' )
39
+ } )
40
+
41
+ test ( 'should switch protocol from https to wss' , ( ) => {
42
+ const client = createClient ( 'https://localhost:3000' , KEY )
43
+
44
+ // @ts -ignore
45
+ const realtimeUrl = client . realtimeUrl
46
+
47
+ expect ( realtimeUrl ) . toEqual ( 'wss://localhost:3000/realtime/v1' )
48
+ } )
49
+
50
+ test ( 'should ignore case' , ( ) => {
51
+ const client = createClient ( 'HTTP://localhost:3000' , KEY )
52
+
53
+ // @ts -ignore
54
+ const realtimeUrl = client . realtimeUrl
55
+
56
+ expect ( realtimeUrl ) . toEqual ( 'ws://localhost:3000/realtime/v1' )
57
+ } )
58
+ } )
59
+
31
60
// Socket should close when there are no open connections
32
61
// https://github.com/supabase/supabase-js/issues/44
33
62
You can’t perform that action at this time.
0 commit comments