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'
|
2022-10-01 18:37:55 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-10-01 18:37:55 +00:00
|
|
|
res.setHeader('Cache-Control', marketCacheStrategy)
|
2022-08-04 05:21:22 +00:00
|
|
|
return res.status(200).json(toLiteMarket(contract))
|
|
|
|
}
|