diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index f6649bf86..c48e0ad69 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -62,13 +62,13 @@ export default class SupabaseClient { if (!supabaseUrl) throw new Error('supabaseUrl is required.') if (!supabaseKey) throw new Error('supabaseKey is required.') - supabaseUrl = stripTrailingSlash(supabaseUrl) - + const _supabaseUrl = stripTrailingSlash(supabaseUrl) const settings = { ...DEFAULT_OPTIONS, ...options } - this.restUrl = `${supabaseUrl}/rest/v1` - this.realtimeUrl = `${supabaseUrl}/realtime/v1`.replace('http', 'ws') - this.authUrl = `${supabaseUrl}/auth/v1` - this.storageUrl = `${supabaseUrl}/storage/v1` + + this.restUrl = `${_supabaseUrl}/rest/v1` + this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws') + this.authUrl = `${_supabaseUrl}/auth/v1` + this.storageUrl = `${_supabaseUrl}/storage/v1` this.schema = settings.schema this.multiTab = settings.multiTab this.fetch = settings.fetch diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index aa90ffc02..3670ff1bb 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -8,7 +8,7 @@ export function uuid() { }) } -export function stripTrailingSlash(url: string) { +export function stripTrailingSlash(url: string): string { return url.replace(/\/$/, '') } diff --git a/test/helper.test.ts b/test/helper.test.ts new file mode 100644 index 000000000..ba422297d --- /dev/null +++ b/test/helper.test.ts @@ -0,0 +1,13 @@ +import { stripTrailingSlash } from '../src/lib/helpers' + +test('Strip trailing slash from URL', () => { + const URL = 'http://localhost:3000/' + const expectedURL = URL.slice(0, -1) + expect(stripTrailingSlash(URL)).toBe(expectedURL) +}) + +test('Return the original URL if there is no slash at the end', () => { + const URL = 'http://localhost:3000' + const expectedURL = URL + expect(stripTrailingSlash(URL)).toBe(expectedURL) +})