The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: studio endpoint to support lazy project loading
phamhieu09a64a1552b3
diff --git a/studio/pages/api/projects/[ref]/index.ts b/studio/pages/api/projects/[ref]/index.tsnew file mode 100644index 00000000000..4c525abd79f--- /dev/null+++ b/studio/pages/api/projects/[ref]/index.ts@@ -0,0 +1,63 @@+import apiWrapper from 'lib/api/apiWrapper'+import { NextApiRequest, NextApiResponse } from 'next'++export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)++async function handler(req: NextApiRequest, res: NextApiResponse) {+ const { method } = req++ switch (method) {+ case 'GET':+ return handleGet(req, res)+ default:+ res.setHeader('Allow', ['GET'])+ res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })+ }+}++const handleGet = async (req: NextApiRequest, res: NextApiResponse) => {+ // Platform specific endpoint+ const response = {+ id: 1,+ ref: 'default',+ name: 'Default Project',+ organization_id: 1,+ cloud_provider: 'localhost',+ status: 'ACTIVE_HEALTHY',+ region: 'local',+ connectionString: createDbConnectionString({+ db_user_supabase: 'postgres',+ db_host: 'localhost',+ db_pass_supabase: process.env.POSTGRES_PASSWORD as string,+ db_port: 5432,+ db_name: 'postgres',+ db_ssl: false,+ }),+ }++ return res.status(200).json(response)+}++/**+ * Creates a Postgres connection string using the Supabase master login.+ * Expects the passwords to be encrypted (straight from the DB)+ */+const createDbConnectionString = ({+ db_user_supabase,+ db_pass_supabase,+ db_host,+ db_port,+ db_name,+ db_ssl,+}: {+ db_user_supabase: string+ db_host: string+ db_pass_supabase: string+ db_port: number+ db_name: string+ db_ssl: boolean+}) => {+ return `postgres://${db_user_supabase}:${db_pass_supabase}@${db_host}:${db_port}/${db_name}?sslmode=${+ db_ssl ? 'require' : 'disable'+ }`+}diff --git a/studio/pages/api/projects/index.ts b/studio/pages/api/projects/index.tsindex 271862d9b69..f708142b571 100644--- a/studio/pages/api/projects/index.ts+++ b/studio/pages/api/projects/index.ts@@ -26,39 +26,7 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {cloud_provider: 'localhost',status: 'ACTIVE_HEALTHY',region: 'local',- connectionString: createDbConnectionString({- db_user_supabase: 'postgres',- db_host: 'localhost',- db_pass_supabase: process.env.POSTGRES_PASSWORD as string,- db_port: 5432,- db_name: 'postgres',- db_ssl: false,- }),},]return res.status(200).json(response)}--/**- * Creates a Postgres connection string using the Supabase master login.- * Expects the passwords to be encrypted (straight from the DB)- */-const createDbConnectionString = ({- db_user_supabase,- db_pass_supabase,- db_host,- db_port,- db_name,- db_ssl,-}: {- db_user_supabase: string- db_host: string- db_pass_supabase: string- db_port: number- db_name: string- db_ssl: boolean-}) => {- return `postgres://${db_user_supabase}:${db_pass_supabase}@${db_host}:${db_port}/${db_name}?sslmode=${- db_ssl ? 'require' : 'disable'- }`-}