manifold/web/pages/api/v0/market/[id]/lite.ts

25 lines
795 B
TypeScript
Raw Normal View History

2022-08-04 05:21:22 +00:00
import { NextApiRequest, NextApiResponse } from 'next'
import { getContractFromId } from 'web/lib/firebase/contracts'
import { applyCorsHeaders, CORS_UNRESTRICTED } from 'web/lib/api/cors'
import { ApiError, toLiteMarket, LiteMarket } from '../../_types'
import { marketCacheStrategy } from '../../markets'
2022-08-04 05:21:22 +00:00
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<LiteMarket | ApiError>
) {
await applyCorsHeaders(req, res, CORS_UNRESTRICTED)
const { id } = req.query
const contractId = id as string
const contract = await getContractFromId(contractId)
if (!contract) {
res.status(404).json({ error: 'Contract not found' })
return
}
res.setHeader('Cache-Control', marketCacheStrategy)
2022-08-04 05:21:22 +00:00
return res.status(200).json(toLiteMarket(contract))
}