api.ts92 lines · main
1import { NextApiRequest, NextApiResponse } from 'next'
2
3import apiWrapper from '@/lib/api/apiWrapper'
4import {
5 DEFAULT_PROJECT,
6 PROJECT_ENDPOINT,
7 PROJECT_ENDPOINT_PROTOCOL,
8 PROJECT_REST_URL,
9} from '@/lib/constants/api'
10
11export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
12
13async function handler(req: NextApiRequest, res: NextApiResponse) {
14 const { method } = req
15
16 switch (method) {
17 case 'GET':
18 return handleGetAll(req, res)
19 default:
20 res.setHeader('Allow', ['GET'])
21 res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
22 }
23}
24
25const handleGetAll = async (_req: NextApiRequest, res: NextApiResponse) => {
26 // Platform specific endpoint
27 const response = {
28 project: {
29 ...DEFAULT_PROJECT,
30 api_key_briven_encrypted: '',
31 db_host: 'localhost',
32 db_name: 'postgres',
33 db_port: 5432,
34 db_ssl: false,
35 db_user: 'postgres',
36 services: [
37 {
38 id: 1,
39 name: 'Default API',
40 app: { id: 1, name: 'Auto API' },
41 app_config: {
42 db_schema: 'public',
43 endpoint: PROJECT_ENDPOINT,
44 realtime_enabled: true,
45 },
46 service_api_keys: [
47 {
48 api_key_encrypted: '-',
49 name: 'service_role key',
50 tags: 'service_role',
51 },
52 {
53 api_key_encrypted: '-',
54 name: 'anon key',
55 tags: 'anon',
56 },
57 ],
58 },
59 ],
60 },
61 autoApiService: {
62 id: 1,
63 name: 'Default API',
64 project: { ref: 'default' },
65 app: { id: 1, name: 'Auto API' },
66 app_config: {
67 db_schema: 'public',
68 endpoint: PROJECT_ENDPOINT,
69 realtime_enabled: true,
70 },
71 protocol: PROJECT_ENDPOINT_PROTOCOL,
72 endpoint: PROJECT_ENDPOINT,
73 restUrl: PROJECT_REST_URL,
74 defaultApiKey: process.env.BRIVEN_ANON_KEY,
75 serviceApiKey: process.env.BRIVEN_SERVICE_KEY,
76 service_api_keys: [
77 {
78 api_key_encrypted: '-',
79 name: 'service_role key',
80 tags: 'service_role',
81 },
82 {
83 api_key_encrypted: '-',
84 name: 'anon key',
85 tags: 'anon',
86 },
87 ],
88 },
89 }
90
91 return res.status(200).json(response)
92}