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<
8484
8585 const _supabaseUrl = stripTrailingSlash ( supabaseUrl )
8686
87- this . realtimeUrl = `${ _supabaseUrl } /realtime/v1` . replace ( ' http' , 'ws' )
87+ this . realtimeUrl = `${ _supabaseUrl } /realtime/v1` . replace ( / ^ h t t p / i , 'ws' )
8888 this . authUrl = `${ _supabaseUrl } /auth/v1`
8989 this . storageUrl = `${ _supabaseUrl } /storage/v1`
9090
Original file line number Diff line number Diff line change @@ -28,6 +28,35 @@ describe('Custom Headers', () => {
2828 } )
2929} )
3030
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+
3160// Socket should close when there are no open connections
3261// https://github.com/supabase/supabase-js/issues/44
3362
You can’t perform that action at this time.
0 commit comments