mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
fix: studio endpoint to support lazy project loading
This commit is contained in:
1 parent
267ff459f6
commit
09a64a1552
2 files changed
+63
-32
No files matched your search
@@ -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'
|
||||
}`
|
||||
}
|
||||
@@ -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'
|
||||
}`
|
||||
}
|
||||
Reference in new issue
Block a user