Skip to content

Commit 331cce3

Browse files
pixtronsoedirgo
authored andcommitted
fix: ignore case when creating realtime url
1 parent 23ae1a8 commit 331cce3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/SupabaseClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(/^http/i, 'ws')
8888
this.authUrl = `${_supabaseUrl}/auth/v1`
8989
this.storageUrl = `${_supabaseUrl}/storage/v1`
9090

test/client.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)