fix: studio endpoint to support lazy project loading

This commit is contained in:
phamhieu authored and Hieu Pham committed 2022-04-07 13:28:52 +07:00
1 parent 267ff459f6
commit 09a64a1552
2 files changed
+63 -32

No files matched your search

+63
View File
@@ -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'
}`
}
-32
View File
@@ -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'
}`
}