From 341cd47cdbf16e1e77d165968aa8852b5547fa74 Mon Sep 17 00:00:00 2001 From: Adam Beck Date: Tue, 14 Sep 2021 13:24:54 -0400 Subject: [PATCH 1/2] Allow for trailing slash in supabaseUrl --- src/SupabaseClient.ts | 3 ++- src/lib/helpers.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index 13a64e73..b94f8bfb 100644 --- a/src/SupabaseClient.ts +++ b/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' @@ -52,7 +53,7 @@ export default class SupabaseClient { if (!supabaseKey) throw new Error('supabaseKey is required.') const settings = { ...DEFAULT_OPTIONS, ...options } - this.restUrl = `${supabaseUrl}/rest/v1` + this.restUrl = `${stripTrailingSlash(supabaseUrl)}/rest/v1` this.realtimeUrl = `${supabaseUrl}/realtime/v1`.replace('http', 'ws') this.authUrl = `${supabaseUrl}/auth/v1` this.storageUrl = `${supabaseUrl}/storage/v1` diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 686282e0..0d9a073d 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -7,3 +7,7 @@ export function uuid() { return v.toString(16) }) } + +export function stripTrailingSlash(url: string) { + return url.replace(/\/$/, ""); +} From 6947602e760e39751ef92cedd2d7ac4c804a79bd Mon Sep 17 00:00:00 2001 From: Adam Beck Date: Tue, 14 Sep 2021 17:38:00 -0400 Subject: [PATCH 2/2] Use for all URLs --- src/SupabaseClient.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index b94f8bfb..83e307a4 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -52,8 +52,10 @@ 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 = `${stripTrailingSlash(supabaseUrl)}/rest/v1` + this.restUrl = `${supabaseUrl}/rest/v1` this.realtimeUrl = `${supabaseUrl}/realtime/v1`.replace('http', 'ws') this.authUrl = `${supabaseUrl}/auth/v1` this.storageUrl = `${supabaseUrl}/storage/v1`