adds self-hosted support for materialized views

This commit is contained in:
Alaister Young committed 2023-04-05 15:50:30 +10:00
1 parent 0e63778668
commit 10cf35aeff
1 file changed
+32
@@ -0,0 +1,32 @@
import { NextApiRequest, NextApiResponse } from 'next'
import apiWrapper from 'lib/api/apiWrapper'
import { get } from 'lib/common/fetch'
import { constructHeaders } from 'lib/api/apiHelpers'
import { PG_META_URL } from 'lib/constants'
export default (req: NextApiRequest, res: NextApiResponse) =>
apiWrapper(req, res, handler, { withAuth: true })
async function handler(req: NextApiRequest, res: NextApiResponse) {
const { method } = req
switch (method) {
case 'GET':
return handleGetAll(req, res)
default:
res.setHeader('Allow', ['GET'])
res.status(405).json({ error: { message: `Method ${method} Not Allowed` } })
}
}
const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {
const headers = constructHeaders(req.headers)
let response = await get(`${PG_META_URL}/materialized-views`, {
headers,
})
if (response.error) {
return res.status(400).json({ error: response.error })
}
return res.status(200).json(response)
}