From 0868ee96f27333cd541dd5d512368a584a510210 Mon Sep 17 00:00:00 2001 From: Inian Date: Wed, 14 Dec 2022 17:27:52 +0800 Subject: [PATCH 1/4] fix: assume http by default if local dev https://localhost had cert issues. the user can override with a https SUPABASE_PUBLIC_URL if required and we will pick that up --- studio/.env | 2 +- .../Home/NewProjectPanel/APIKeys.tsx | 5 +-- .../storageExplorer/StorageExplorerStore.js | 33 +++++++++++-------- studio/pages/api/constants.ts | 3 +- studio/pages/project/[ref]/api/index.tsx | 3 +- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/studio/.env b/studio/.env index d872e21ab40..90e1f679821 100644 --- a/studio/.env +++ b/studio/.env @@ -5,7 +5,7 @@ DEFAULT_ORGANIZATION_NAME=Default Organization DEFAULT_PROJECT_NAME=Default Project SUPABASE_URL=http://localhost:8000 -SUPABASE_PUBLIC_URL=https://localhost:8443 +SUPABASE_PUBLIC_URL=http://localhost:8000 SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q diff --git a/studio/components/interfaces/Home/NewProjectPanel/APIKeys.tsx b/studio/components/interfaces/Home/NewProjectPanel/APIKeys.tsx index a70a125cc0b..ac11e16bd6f 100644 --- a/studio/components/interfaces/Home/NewProjectPanel/APIKeys.tsx +++ b/studio/components/interfaces/Home/NewProjectPanel/APIKeys.tsx @@ -6,7 +6,8 @@ import { JwtSecretUpdateStatus } from '@supabase/shared-types/out/events' import { PermissionAction } from '@supabase/shared-types/out/constants' import { checkPermissions, useJwtSecretUpdateStatus, useProjectSettings } from 'hooks' -import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants' +import { DEFAULT_PROJECT_API_SERVICE_ID, IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' import Snippets from 'components/to-be-cleaned/Docs/Snippets' import Panel from 'components/ui/Panel' import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock' @@ -45,7 +46,7 @@ const APIKeys = () => { const isNotUpdatingJwtSecret = jwtSecretUpdateStatus === undefined || jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updated - const apiUrl = `https://${apiConfig.endpoint}` + const apiUrl = `${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${apiConfig.endpoint}` const anonKey = apiKeys.find((key: any) => key.tags === 'anon') const clientInitSnippet: any = Snippets.init(apiUrl) diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js index f3bcfd79a4b..bf6a2a1f8bb 100644 --- a/studio/localStores/storageExplorer/StorageExplorerStore.js +++ b/studio/localStores/storageExplorer/StorageExplorerStore.js @@ -24,6 +24,8 @@ import { STORAGE_SORT_BY, } from 'components/to-be-cleaned/Storage/Storage.constants.ts' import { copyToClipboard } from 'lib/helpers' +import { IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' /** * This is a preferred method rather than React Context and useStorageExplorerStore(). @@ -112,21 +114,26 @@ class StorageExplorerStore { /* Methods which are commonly used + For better readability */ initializeSupabaseClient = (serviceKey, serviceEndpoint) => { - this.supabaseClient = createClient(`https://${serviceEndpoint}`, serviceKey, { - auth: { - persistSession: false, - autoRefreshToken: false, - multiTab: false, - detectSessionInUrl: false, - localStorage: { - getItem: (key) => { - return undefined + console.log(serviceEndpoint) + this.supabaseClient = createClient( + `${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${serviceEndpoint}`, + serviceKey, + { + auth: { + persistSession: false, + autoRefreshToken: false, + multiTab: false, + detectSessionInUrl: false, + localStorage: { + getItem: (key) => { + return undefined + }, + setItem: (key, value) => {}, + removeItem: (key) => {}, }, - setItem: (key, value) => {}, - removeItem: (key) => {}, }, - }, - }) + } + ) } updateFileInPreviewCache = (fileCache) => { diff --git a/studio/pages/api/constants.ts b/studio/pages/api/constants.ts index 3531bad779e..ae150beae97 100644 --- a/studio/pages/api/constants.ts +++ b/studio/pages/api/constants.ts @@ -1,4 +1,5 @@ -const PUBLIC_URL = new URL(process.env.SUPABASE_PUBLIC_URL || 'https://localhost:8443') +const PUBLIC_URL = new URL(process.env.SUPABASE_PUBLIC_URL || 'http://localhost:8000') export const PROJECT_REST_URL = `${PUBLIC_URL.origin}/rest/v1/` export const PROJECT_ENDPOINT = PUBLIC_URL.host +export const PROJECT_ENDPOINT_PROTOCOL = PUBLIC_URL.protocol.replace(':', '') diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsx index 8b4cfaa92f4..482494908ff 100644 --- a/studio/pages/project/[ref]/api/index.tsx +++ b/studio/pages/project/[ref]/api/index.tsx @@ -6,6 +6,7 @@ import { observer, useLocalObservable } from 'mobx-react-lite' import { NextPageWithLayout } from 'types' import { API_URL, IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' import { checkPermissions, useStore } from 'hooks' import { get } from 'lib/common/fetch' import { snakeToCamel } from 'lib/helpers' @@ -118,7 +119,7 @@ const DocView: FC = observer(({}) => { ...data.autoApiService, endpoint: IS_PLATFORM ? `https://${data?.autoApiService?.endpoint}` - : data.autoApiService.endpoint, + : `${PROJECT_ENDPOINT_PROTOCOL}://${data.autoApiService.endpoint}`, } const { query } = router From 4c2f589404070ef94ccd27cc4833ce13db5ad6e0 Mon Sep 17 00:00:00 2001 From: Inian Date: Wed, 14 Dec 2022 17:44:03 +0800 Subject: [PATCH 2/4] Update studio/localStores/storageExplorer/StorageExplorerStore.js Co-authored-by: Han Qiao --- studio/localStores/storageExplorer/StorageExplorerStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js index bf6a2a1f8bb..d553efa0f76 100644 --- a/studio/localStores/storageExplorer/StorageExplorerStore.js +++ b/studio/localStores/storageExplorer/StorageExplorerStore.js @@ -114,7 +114,7 @@ class StorageExplorerStore { /* Methods which are commonly used + For better readability */ initializeSupabaseClient = (serviceKey, serviceEndpoint) => { - console.log(serviceEndpoint) + console.debug(serviceEndpoint) this.supabaseClient = createClient( `${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${serviceEndpoint}`, serviceKey, From bb04bb271bb5e8f3b961f7f436bab85fbc4a08cf Mon Sep 17 00:00:00 2001 From: Inian Date: Wed, 14 Dec 2022 17:45:49 +0800 Subject: [PATCH 3/4] fix: protocol for vercel integration on local dev --- studio/pages/vercel/integrate.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/studio/pages/vercel/integrate.tsx b/studio/pages/vercel/integrate.tsx index 13956ad8251..424df36774d 100644 --- a/studio/pages/vercel/integrate.tsx +++ b/studio/pages/vercel/integrate.tsx @@ -10,7 +10,8 @@ import Divider from 'components/ui/Divider' import { Dictionary } from 'components/grid' import { useStore, withAuth } from 'hooks' -import { API_URL } from 'lib/constants' +import { API_URL, IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' import { get } from 'lib/common/fetch' import { VERCEL_INTEGRATION_CONFIGS, @@ -280,7 +281,7 @@ const IntegrationProject: FC = observer(() => {
@@ -369,7 +370,9 @@ const ProjectLinks: FC = observer(() => { // Then create env for vercel project with supabase project const vercelEnvs = prepareVercelEvns(defaultVercelEnvs, { - endpoint: `https://${projectDetails.autoApiService.endpoint}`, + endpoint: `${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${ + projectDetails.autoApiService.endpoint + }`, anon_key: projectDetails.autoApiService.defaultApiKey, service_key: projectDetails.autoApiService.serviceApiKey, }) From 3070064cc54b82a84c5eff4810170e40277e772d Mon Sep 17 00:00:00 2001 From: Inian Date: Wed, 14 Dec 2022 18:01:25 +0800 Subject: [PATCH 4/4] fix: protocol fixes in more places --- studio/components/interfaces/Settings/API/ServiceList.tsx | 6 +++++- .../components/ui/ProjectSettings/DisplayConfigSettings.tsx | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/studio/components/interfaces/Settings/API/ServiceList.tsx b/studio/components/interfaces/Settings/API/ServiceList.tsx index aba88820aac..ce2097d0b03 100644 --- a/studio/components/interfaces/Settings/API/ServiceList.tsx +++ b/studio/components/interfaces/Settings/API/ServiceList.tsx @@ -14,6 +14,8 @@ import Panel from 'components/ui/Panel' import PostgrestConfig from './PostgrestConfig' import { DisplayApiSettings } from 'components/ui/ProjectSettings' import { JWT_SECRET_UPDATE_ERROR_MESSAGES } from './API.constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' +import { IS_PLATFORM } from 'lib/constants' import JWTSettings from './JWTSettings' interface Props { @@ -77,7 +79,9 @@ const ServiceList: FC = ({ projectRef }) => { readOnly disabled className="input-mono" - value={`https://${apiConfig?.endpoint ?? '-'}`} + value={`${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${ + apiConfig?.endpoint ?? '-' + }`} descriptionText="A RESTful endpoint for querying and managing your database." layout="horizontal" /> diff --git a/studio/components/ui/ProjectSettings/DisplayConfigSettings.tsx b/studio/components/ui/ProjectSettings/DisplayConfigSettings.tsx index d43f8a3d478..ea70fb700dd 100644 --- a/studio/components/ui/ProjectSettings/DisplayConfigSettings.tsx +++ b/studio/components/ui/ProjectSettings/DisplayConfigSettings.tsx @@ -3,7 +3,8 @@ import { useRouter } from 'next/router' import { Input, IconAlertCircle, IconLoader } from 'ui' import { JwtSecretUpdateStatus } from '@supabase/shared-types/out/events' import { useJwtSecretUpdateStatus, useProjectSettings } from 'hooks' -import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants' +import { DEFAULT_PROJECT_API_SERVICE_ID, IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' import Panel from 'components/ui/Panel' const DisplayConfigSettings = () => { @@ -55,7 +56,7 @@ const DisplayConfigSettings = () => { copy disabled className="input-mono" - value={`https://${apiConfig.endpoint}`} + value={`${IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL}://${apiConfig.endpoint}`} descriptionText="A RESTful endpoint for querying and managing your database." layout="horizontal" />