From 9c63fc53bb397e16b700b933c58c4ca5bd68f322 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Wed, 16 Nov 2022 11:11:30 +0800 Subject: [PATCH] chore: use supabase public url --- docker/.env.example | 2 +- docker/docker-compose.yml | 11 +++++++---- studio/.env | 3 +-- .../layouts/StorageLayout/StorageMenu.tsx | 1 - .../storageExplorer/StorageExplorerStore.js | 3 +-- studio/package.json | 2 +- studio/pages/api/constants.ts | 4 ++++ studio/pages/api/projects/[ref]/index.ts | 3 ++- studio/pages/api/props/project/[ref]/api.ts | 13 +++++++------ studio/pages/api/props/project/[ref]/settings.ts | 3 ++- 10 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 studio/pages/api/constants.ts diff --git a/docker/.env.example b/docker/.env.example index 3d68946481..2469e01fa6 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -74,4 +74,4 @@ STUDIO_DEFAULT_ORGANIZATION=Default Organization STUDIO_DEFAULT_PROJECT=Default Project STUDIO_PORT=3000 -SUPABASE_PUBLIC_URL=http://localhost:8000 # replace if you intend to use Studio outside of localhost +SUPABASE_PUBLIC_URL=https://localhost:8443 # replace if you intend to use Studio outside of localhost diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 2bf444e5aa..cfb99e5423 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -21,7 +21,9 @@ services: DEFAULT_PROJECT: ${STUDIO_DEFAULT_PROJECT} SUPABASE_URL: http://kong:8000 - SUPABASE_REST_URL: ${SUPABASE_PUBLIC_URL} + SUPABASE_PUBLIC_URL: ${SUPABASE_PUBLIC_URL} + # Kept for backwards compatibility with studio:0.22.08 + SUPABASE_REST_URL: ${API_EXTERNAL_URL}/rest/v1/ SUPABASE_ANON_KEY: ${ANON_KEY} SUPABASE_SERVICE_KEY: ${SERVICE_ROLE_KEY} @@ -45,7 +47,7 @@ services: auth: container_name: supabase-auth - image: supabase/gotrue:v2.19.4 + image: supabase/gotrue:v2.25.1 depends_on: db: # Disable this if you are using an external Postgres database condition: service_healthy @@ -122,7 +124,8 @@ services: SLOT_NAME: supabase_realtime_rls TEMPORARY_SLOT: "true" command: > - bash -c "./prod/rel/realtime/bin/realtime eval Realtime.Release.migrate && ./prod/rel/realtime/bin/realtime start" + bash -c "./prod/rel/realtime/bin/realtime eval Realtime.Release.migrate + && ./prod/rel/realtime/bin/realtime start" storage: container_name: supabase-storage @@ -167,7 +170,7 @@ services: # Comment out everything below this point if you are using an external Postgres database db: container_name: supabase-db - image: supabase/postgres:14.1.0.82 + image: supabase/postgres:14.1.0.89 healthcheck: test: pg_isready -U postgres -h localhost interval: 5s diff --git a/studio/.env b/studio/.env index dd9c8a3205..ee686048df 100644 --- a/studio/.env +++ b/studio/.env @@ -5,7 +5,6 @@ DEFAULT_ORGANIZATION_NAME=Default Organization DEFAULT_PROJECT_NAME=Default Project SUPABASE_URL=http://localhost:8000 -SUPABASE_REST_URL=http://localhost:8000 +SUPABASE_PUBLIC_URL=https://localhost:8443 SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q - diff --git a/studio/components/layouts/StorageLayout/StorageMenu.tsx b/studio/components/layouts/StorageLayout/StorageMenu.tsx index 218408594c..dc41cdacb6 100644 --- a/studio/components/layouts/StorageLayout/StorageMenu.tsx +++ b/studio/components/layouts/StorageLayout/StorageMenu.tsx @@ -18,7 +18,6 @@ import { import ProductMenuItem from 'components/ui/ProductMenu/ProductMenuItem' import { STORAGE_ROW_STATUS } from 'components/to-be-cleaned/Storage/Storage.constants' import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore' -import { IS_PLATFORM } from 'lib/constants' interface Props {} diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js index 9c66811368..f3bcfd79a4 100644 --- a/studio/localStores/storageExplorer/StorageExplorerStore.js +++ b/studio/localStores/storageExplorer/StorageExplorerStore.js @@ -112,7 +112,7 @@ class StorageExplorerStore { /* Methods which are commonly used + For better readability */ initializeSupabaseClient = (serviceKey, serviceEndpoint) => { - this.supabaseClient = createClient(`${serviceEndpoint}`, serviceKey, { + this.supabaseClient = createClient(`https://${serviceEndpoint}`, serviceKey, { auth: { persistSession: false, autoRefreshToken: false, @@ -478,7 +478,6 @@ class StorageExplorerStore { fetchBuckets = async () => { const { data: buckets, error } = await this.supabaseClient.storage.listBuckets() - if (error) return this.ui.setNotification({ message: error.message, category: 'error' }) const formattedBuckets = buckets.map((bucket) => { diff --git a/studio/package.json b/studio/package.json index bba48626c3..587ba186cf 100644 --- a/studio/package.json +++ b/studio/package.json @@ -3,7 +3,7 @@ "version": "0.0.9", "private": true, "scripts": { - "dev": "next dev -p 3000", + "dev": "next dev -p 8082", "build": "next build", "start": "next start", "test": "jest", diff --git a/studio/pages/api/constants.ts b/studio/pages/api/constants.ts new file mode 100644 index 0000000000..3531bad779 --- /dev/null +++ b/studio/pages/api/constants.ts @@ -0,0 +1,4 @@ +const PUBLIC_URL = new URL(process.env.SUPABASE_PUBLIC_URL || 'https://localhost:8443') + +export const PROJECT_REST_URL = `${PUBLIC_URL.origin}/rest/v1/` +export const PROJECT_ENDPOINT = PUBLIC_URL.host diff --git a/studio/pages/api/projects/[ref]/index.ts b/studio/pages/api/projects/[ref]/index.ts index 204167ae37..7ae98b66a3 100644 --- a/studio/pages/api/projects/[ref]/index.ts +++ b/studio/pages/api/projects/[ref]/index.ts @@ -1,6 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import apiWrapper from 'lib/api/apiWrapper' +import { PROJECT_REST_URL } from 'pages/api/constants' export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) @@ -35,7 +36,7 @@ const handleGet = async (req: NextApiRequest, res: NextApiResponse) => { db_ssl: false, }), kpsVersion: 'kps-v1.0.0', - restUrl: `${process.env.SUPABASE_REST_URL}/rest/v1/` || 'http://localhost:8000/rest/v1/', + restUrl: PROJECT_REST_URL, } return res.status(200).json(response) diff --git a/studio/pages/api/props/project/[ref]/api.ts b/studio/pages/api/props/project/[ref]/api.ts index 9736e3cdc4..9e6cb871c4 100644 --- a/studio/pages/api/props/project/[ref]/api.ts +++ b/studio/pages/api/props/project/[ref]/api.ts @@ -1,6 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import apiWrapper from 'lib/api/apiWrapper' +import { PROJECT_ENDPOINT, PROJECT_REST_URL } from 'pages/api/constants' export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) @@ -39,11 +40,11 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => { app: { id: 1, name: 'Auto API' }, app_config: { db_schema: 'public', - endpoint: process.env.SUPABASE_URL, + endpoint: PROJECT_ENDPOINT, realtime_enabled: true, }, - endpoint: process.env.SUPABASE_URL || 'http://localhost:8000', - restUrl: `${process.env.SUPABASE_REST_URL}/rest/v1/` || 'http://localhost:8000/rest/v1/', + endpoint: PROJECT_ENDPOINT, + restUrl: PROJECT_REST_URL, defaultApiKey: process.env.SUPABASE_ANON_KEY, serviceApiKey: process.env.SUPABASE_SERVICE_KEY, service_api_keys: [ @@ -68,11 +69,11 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => { app: { id: 1, name: 'Auto API' }, app_config: { db_schema: 'public', - endpoint: process.env.SUPABASE_URL, + endpoint: PROJECT_ENDPOINT, realtime_enabled: true, }, - endpoint: process.env.SUPABASE_URL, - restUrl: `${process.env.SUPABASE_REST_URL}/rest/v1/`, + endpoint: PROJECT_ENDPOINT, + restUrl: PROJECT_REST_URL, defaultApiKey: process.env.SUPABASE_ANON_KEY, serviceApiKey: process.env.SUPABASE_SERVICE_KEY, service_api_keys: [ diff --git a/studio/pages/api/props/project/[ref]/settings.ts b/studio/pages/api/props/project/[ref]/settings.ts index 5677414b23..433ee7f95c 100644 --- a/studio/pages/api/props/project/[ref]/settings.ts +++ b/studio/pages/api/props/project/[ref]/settings.ts @@ -1,6 +1,7 @@ import { NextApiRequest, NextApiResponse } from 'next' import apiWrapper from 'lib/api/apiWrapper' +import { PROJECT_ENDPOINT } from 'pages/api/constants' export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) @@ -56,7 +57,7 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => { app: { id: 1, name: 'Auto API' }, app_config: { db_schema: 'public', - endpoint: process.env.SUPABASE_URL, + endpoint: PROJECT_ENDPOINT, realtime_enabled: true, }, },