Skip to content

Commit

Permalink
fix: ignore case when creating realtime url
Browse files Browse the repository at this point in the history
  • Loading branch information
pixtron authored and soedirgo committed Aug 29, 2022
1 parent 23ae1a8 commit 331cce3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SupabaseClient.ts
Expand Up @@ -84,7 +84,7 @@ export default class SupabaseClient<

const _supabaseUrl = stripTrailingSlash(supabaseUrl)

this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws')
this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace(/^http/i, 'ws')
this.authUrl = `${_supabaseUrl}/auth/v1`
this.storageUrl = `${_supabaseUrl}/storage/v1`

Expand Down
29 changes: 29 additions & 0 deletions test/client.test.ts
Expand Up @@ -28,6 +28,35 @@ describe('Custom Headers', () => {
})
})

describe('Realtime url', () => {
test('should switch protocol from http to ws', () => {
const client = createClient('http://localhost:3000', KEY)

// @ts-ignore
const realtimeUrl = client.realtimeUrl

expect(realtimeUrl).toEqual('ws://localhost:3000/realtime/v1')
})

test('should switch protocol from https to wss', () => {
const client = createClient('https://localhost:3000', KEY)

// @ts-ignore
const realtimeUrl = client.realtimeUrl

expect(realtimeUrl).toEqual('wss://localhost:3000/realtime/v1')
})

test('should ignore case', () => {
const client = createClient('HTTP://localhost:3000', KEY)

// @ts-ignore
const realtimeUrl = client.realtimeUrl

expect(realtimeUrl).toEqual('ws://localhost:3000/realtime/v1')
})
})

// Socket should close when there are no open connections
// https://github.com/supabase/supabase-js/issues/44

Expand Down

0 comments on commit 331cce3

Please sign in to comment.