Skip to content

Commit b7f693f

Browse files
authored
Merge pull request #279 from ftonato/fix/trailing-slash
refactor: add some small changes to stripTrailingSlash method
2 parents f9ef9f3 + 868c4a0 commit b7f693f

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/SupabaseClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ export default class SupabaseClient {
6262
if (!supabaseUrl) throw new Error('supabaseUrl is required.')
6363
if (!supabaseKey) throw new Error('supabaseKey is required.')
6464

65-
supabaseUrl = stripTrailingSlash(supabaseUrl)
66-
65+
const _supabaseUrl = stripTrailingSlash(supabaseUrl)
6766
const settings = { ...DEFAULT_OPTIONS, ...options }
68-
this.restUrl = `${supabaseUrl}/rest/v1`
69-
this.realtimeUrl = `${supabaseUrl}/realtime/v1`.replace('http', 'ws')
70-
this.authUrl = `${supabaseUrl}/auth/v1`
71-
this.storageUrl = `${supabaseUrl}/storage/v1`
67+
68+
this.restUrl = `${_supabaseUrl}/rest/v1`
69+
this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws')
70+
this.authUrl = `${_supabaseUrl}/auth/v1`
71+
this.storageUrl = `${_supabaseUrl}/storage/v1`
7272
this.schema = settings.schema
7373
this.multiTab = settings.multiTab
7474
this.fetch = settings.fetch

src/lib/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function uuid() {
88
})
99
}
1010

11-
export function stripTrailingSlash(url: string) {
11+
export function stripTrailingSlash(url: string): string {
1212
return url.replace(/\/$/, '')
1313
}
1414

test/helper.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { stripTrailingSlash } from '../src/lib/helpers'
2+
3+
test('Strip trailing slash from URL', () => {
4+
const URL = 'http://localhost:3000/'
5+
const expectedURL = URL.slice(0, -1)
6+
expect(stripTrailingSlash(URL)).toBe(expectedURL)
7+
})
8+
9+
test('Return the original URL if there is no slash at the end', () => {
10+
const URL = 'http://localhost:3000'
11+
const expectedURL = URL
12+
expect(stripTrailingSlash(URL)).toBe(expectedURL)
13+
})

0 commit comments

Comments
 (0)