2022-02-17 20:56:24 +00:00
|
|
|
// Next.js API route support: https://vercel.com/docs/concepts/functions/serverless-functions
|
|
|
|
import type { NextApiRequest, NextApiResponse } from 'next'
|
|
|
|
import { listAllContracts } from '../../../lib/firebase/contracts'
|
2022-02-17 23:22:51 +00:00
|
|
|
import { toLiteMarket } from './_types'
|
2022-02-17 20:56:24 +00:00
|
|
|
|
|
|
|
type Data = any[]
|
|
|
|
|
|
|
|
export default async function handler(
|
|
|
|
req: NextApiRequest,
|
|
|
|
res: NextApiResponse<Data>
|
|
|
|
) {
|
|
|
|
const contracts = await listAllContracts()
|
|
|
|
// Serve from Vercel cache, then update. see https://vercel.com/docs/concepts/functions/edge-caching
|
|
|
|
res.setHeader('Cache-Control', 's-maxage=1, stale-while-revalidate')
|
2022-02-17 23:22:51 +00:00
|
|
|
res.status(200).json(contracts.map(toLiteMarket))
|
2022-02-17 20:56:24 +00:00
|
|
|
}
|