postgrest.ts32 lines · main
| 1 | import { components } from 'api-types' |
| 2 | import { NextApiRequest, NextApiResponse } from 'next' |
| 3 | |
| 4 | import apiWrapper from '@/lib/api/apiWrapper' |
| 5 | |
| 6 | export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) |
| 7 | |
| 8 | async function handler(req: NextApiRequest, res: NextApiResponse) { |
| 9 | const { method } = req |
| 10 | |
| 11 | switch (method) { |
| 12 | case 'GET': |
| 13 | return handleGet(req, res) |
| 14 | default: |
| 15 | res.setHeader('Allow', ['GET']) |
| 16 | res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } }) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | const handleGet = async (_req: NextApiRequest, res: NextApiResponse) => { |
| 21 | const responseObj: components['schemas']['GetPostgrestConfigResponse'] = { |
| 22 | db_anon_role: 'anon', |
| 23 | db_extra_search_path: process.env.PGRST_DB_EXTRA_SEARCH_PATH ?? 'public', |
| 24 | db_schema: process.env.PGRST_DB_SCHEMAS ?? 'public,storage,graphql_public', |
| 25 | jwt_secret: |
| 26 | process.env.AUTH_JWT_SECRET ?? 'super-secret-jwt-token-with-at-least-32-characters-long', |
| 27 | max_rows: Number(process.env.PGRST_DB_MAX_ROWS) || 1000, |
| 28 | role_claim_key: '.role', |
| 29 | } |
| 30 | |
| 31 | return res.status(200).json(responseObj) |
| 32 | } |