From 3e2d2718c38783f3c8b398f2577e2892c386e5cc Mon Sep 17 00:00:00 2001 From: titix Date: Wed, 8 May 2024 18:01:19 -0300 Subject: [PATCH] fix: post req --- src/pages/api/logs.ts | 26 +++++++++++--------------- src/utils/logs.ts | 13 ++++++------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/pages/api/logs.ts b/src/pages/api/logs.ts index 9769587..6a92091 100644 --- a/src/pages/api/logs.ts +++ b/src/pages/api/logs.ts @@ -1,24 +1,20 @@ import type { NextApiRequest, NextApiResponse } from 'next'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const referer = req.headers.referer; + if (req.method === 'POST') { + try { + const { id, merkle_root, nullifier_hash, proof, error } = req.body; + const logData = { id, merkle_root, nullifier_hash, proof, error }; - const allowedReferers = ['https://www.moregoats.com/', 'https://dev.moregoats.com/']; + console.log(logData); - if (!referer || !allowedReferers.includes(referer)) { - res.status(403).json({ error: 'Unauthorized access' }); - return; - } - - if (req.method === 'GET') { - const { id, merkle_root, nullifier_hash, proof, error } = req.query; - const logData = { id, merkle_root, nullifier_hash, proof, error }; - - console.log(logData); - - res.status(200).json({ message: 'Log successful', log: logData }); + res.status(200).json({ message: 'Log successful', log: logData }); + } catch (error) { + console.error('Error processing the request:', error); + res.status(500).json({ error: 'Error processing the request' }); + } } else { - res.setHeader('Allow', ['GET']); + res.setHeader('Allow', ['POST']); res.status(405).end(`Method ${req.method} Not Allowed`); } } diff --git a/src/utils/logs.ts b/src/utils/logs.ts index 9feefe2..273ba4d 100644 --- a/src/utils/logs.ts +++ b/src/utils/logs.ts @@ -8,14 +8,13 @@ interface LogEntry { export async function sendLog(data: LogEntry) { try { - const response = await fetch( - `/api/logs?id=${data.id}&proof=${data.proof}&merkle_root=${data.merkle_root}&nullifier_hash=${ - data.nullifier_hash - }&error=${data.error || null}`, - { - method: 'GET', + const response = await fetch('/api/logs', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', }, - ); + body: JSON.stringify(data), + }); if (!response.ok) { throw new Error('Failed to send log data');