From 7e46188107518aeb6e83a2e6e77bf8ec3965971c Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 3 Aug 2022 22:21:22 -0700 Subject: [PATCH] Add lite market endpoint --- web/pages/api/v0/market/[id]/lite.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 web/pages/api/v0/market/[id]/lite.ts diff --git a/web/pages/api/v0/market/[id]/lite.ts b/web/pages/api/v0/market/[id]/lite.ts new file mode 100644 index 00000000..7688caa8 --- /dev/null +++ b/web/pages/api/v0/market/[id]/lite.ts @@ -0,0 +1,23 @@ +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' + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + 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', 'max-age=0') + return res.status(200).json(toLiteMarket(contract)) +}