diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/api.js | 39 |
1 files changed, 14 insertions, 25 deletions
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(); }; |