manifold/web/pages/api/v0/markets.ts
Marshall Polaris 731e5d5b7c
Apply permissive CORS headers to API (#115)
* Take cors package as dependency

* Apply permissive CORS headers to all API routes
2022-04-30 13:30:49 -07:00

19 lines
779 B
TypeScript

// 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'
import { toLiteMarket } from './_types'
import { applyCorsHeaders, CORS_UNRESTRICTED } from '../../../lib/api/cors'
type Data = any[]
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
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')
res.status(200).json(contracts.map(toLiteMarket))
}