From 46b00016a2656b8a9d754fa5d045f1289cca45dc Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Sat, 14 May 2022 20:20:17 +0200 Subject: [PATCH] Allow to override Supabase service URLs in client Add 4 options to SupabaseClient that allow to set urls for Supabase services: REST, Realtime, Auth, Storage, by option keys restUrl, realtimeUrl, authUrl and storageUrl. The option should contain full url (eg. https://foo.com/auth/v1 for GoTrue hosted at such url.) --- src/SupabaseClient.ts | 8 ++++---- src/lib/types.ts | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/SupabaseClient.ts b/src/SupabaseClient.ts index 5e12c835..79c55ca9 100644 --- a/src/SupabaseClient.ts +++ b/src/SupabaseClient.ts @@ -74,10 +74,10 @@ export default class SupabaseClient { 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 = options?.restUrl || `${_supabaseUrl}/rest/v1` + this.realtimeUrl = options?.realtimeUrl || `${_supabaseUrl}/realtime/v1`.replace('http', 'ws') + this.authUrl = options?.authUrl || `${_supabaseUrl}/auth/v1` + this.storageUrl = options?.storageUrl || `${_supabaseUrl}/storage/v1` const isPlatform = _supabaseUrl.match(/(supabase\.co)|(supabase\.in)/) if (isPlatform) { diff --git a/src/lib/types.ts b/src/lib/types.ts index 5872cb41..dab267a8 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -58,6 +58,26 @@ export type SupabaseClientOptions = { * Options passed to the gotrue-js instance */ cookieOptions?: SupabaseAuthClientOptions['cookieOptions'] + + /** + * Override the restUrl + */ + restUrl?: string + + /** + * Override the realtimeUrl (must be ws:// scheme) + */ + realtimeUrl?: string + + /** + * Override the authUrl + */ + authUrl?: string + + /** + * Override the storageUrl + */ + storageUrl?: string } export type SupabaseRealtimePayload = {