From b1c4f018f96b44161e09d68ec1abf2c9bedcd52e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 27 Jul 2022 17:38:25 -0700 Subject: [PATCH] Expose cancel bet api --- web/pages/api/v0/bet/cancel/[betId].ts | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 web/pages/api/v0/bet/cancel/[betId].ts diff --git a/web/pages/api/v0/bet/cancel/[betId].ts b/web/pages/api/v0/bet/cancel/[betId].ts new file mode 100644 index 00000000..878b9349 --- /dev/null +++ b/web/pages/api/v0/bet/cancel/[betId].ts @@ -0,0 +1,27 @@ +import { NextApiRequest, NextApiResponse } from 'next' +import { + CORS_ORIGIN_MANIFOLD, + CORS_ORIGIN_LOCALHOST, +} from 'common/envs/constants' +import { applyCorsHeaders } from 'web/lib/api/cors' +import { fetchBackend, forwardResponse } from 'web/lib/api/proxy' + +export const config = { api: { bodyParser: true } } + +export default async function route(req: NextApiRequest, res: NextApiResponse) { + await applyCorsHeaders(req, res, { + origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST], + methods: 'POST', + }) + + const { betId } = req.query as { betId: string } + + if (req.body) req.body.betId = betId + try { + const backendRes = await fetchBackend(req, 'cancelbet') + await forwardResponse(res, backendRes) + } catch (err) { + console.error('Error talking to cloud function: ', err) + res.status(500).json({ message: 'Error communicating with backend.' }) + } +}