From 55aed6d7c2df0daedbdabea0d1727acb1815ce2b Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Fri, 26 Jul 2024 21:21:03 +0530 Subject: added upload feature --- src/utils/api.js | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src/utils') diff --git a/src/utils/api.js b/src/utils/api.js index 1f8e92d..7b63aa4 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,32 +1,21 @@ -const API_URL = 'http://localhost:5000'; // Replace with your actual API URL - export const fetchAds = async () => { - try { - const response = await fetch(`${API_URL}/ads`); - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return await response.json(); - } catch (error) { - console.error('Error fetching ads:', error); - return []; + const response = await fetch('http://localhost:5000/ads'); + if (!response.ok) { + throw new Error('Network response was not ok'); } + return response.json(); }; export const addAd = async (ad) => { - try { - const response = await fetch(`${API_URL}/ads`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(ad), - }); - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return await response.json(); - } catch (error) { - console.error('Error adding ad:', error); + const response = await fetch('http://localhost:5000/ads', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(ad), + }); + if (!response.ok) { + throw new Error('Network response was not ok'); } + return response.json(); }; -- cgit v1.2.3-59-g8ed1b