Skip to content

Commit

Permalink
fix: Allow for trailing slash in supabaseUrl (#262)
Browse files Browse the repository at this point in the history
* Allow for trailing slash in supabaseUrl

* Use for all URLs
  • Loading branch information
adam-beck committed Sep 28, 2021
1 parent 7ad1d09 commit 64f77ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SupabaseClient.ts
@@ -1,4 +1,5 @@
import { DEFAULT_HEADERS } from './lib/constants'
import { stripTrailingSlash } from './lib/helpers'
import { SupabaseClientOptions } from './lib/types'
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
Expand Down Expand Up @@ -51,6 +52,8 @@ export default class SupabaseClient {
if (!supabaseUrl) throw new Error('supabaseUrl is required.')
if (!supabaseKey) throw new Error('supabaseKey is required.')

supabaseUrl = stripTrailingSlash(supabaseUrl)

const settings = { ...DEFAULT_OPTIONS, ...options }
this.restUrl = `${supabaseUrl}/rest/v1`
this.realtimeUrl = `${supabaseUrl}/realtime/v1`.replace('http', 'ws')
Expand Down
4 changes: 4 additions & 0 deletions src/lib/helpers.ts
Expand Up @@ -7,3 +7,7 @@ export function uuid() {
return v.toString(16)
})
}

export function stripTrailingSlash(url: string) {
return url.replace(/\/$/, "");
}

0 comments on commit 64f77ee

Please sign in to comment.