From 0097ded29a36464c83b756b7c8b71873f9ea3d80 Mon Sep 17 00:00:00 2001 From: Luxshan2000 Date: Fri, 29 Sep 2023 05:21:37 +0530 Subject: [PATCH] finalized --- backend/server.js | 3 ++- backend/src/controllers/addData.js | 1 + frontend/src/App.js | 4 ++-- frontend/src/components/AddItems.js | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/server.js b/backend/server.js index 47484f8..b6d1f2c 100644 --- a/backend/server.js +++ b/backend/server.js @@ -10,7 +10,8 @@ const app = express() const PORT = process.env.PORT || 5000 app.use(cors({ - origin:["*", "http://51.20.93.112:3000"],//"exp://192.168.8.182:8081" + //51.20.93.112 + origin:["*", "http://localhost:3000"],//"exp://192.168.8.182:8081" methods:["GET","POST"], credentials:true })) diff --git a/backend/src/controllers/addData.js b/backend/src/controllers/addData.js index f44628c..26a91d7 100644 --- a/backend/src/controllers/addData.js +++ b/backend/src/controllers/addData.js @@ -14,6 +14,7 @@ exports.addItem = async (req,res) =>{ console.log("Successfully meal added!") + res.json({status:"Success", item:newItem }) } catch(error){ diff --git a/frontend/src/App.js b/frontend/src/App.js index 1c96ad4..fb1cece 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -7,8 +7,8 @@ import { useEffect, useState } from 'react'; function App() { const [items, setItems] = useState([]) - useEffect(()=>{ - axios.get("http://51.20.93.112:5000/api/get/items").then(response => { + useEffect(()=>{//51.20.93.112 + axios.get("http://localhost:5000/api/get/items").then(response => { setItems(response.data) }) diff --git a/frontend/src/components/AddItems.js b/frontend/src/components/AddItems.js index c54a48f..0588486 100644 --- a/frontend/src/components/AddItems.js +++ b/frontend/src/components/AddItems.js @@ -8,9 +8,10 @@ function AddItems({setItems}) { const handleSubmit = async (ev) => { ev.preventDefault(); - try { - await axios.post("http://51.20.93.112:5000/api/add/item", { name: name }); + try {//51.20.93.112 + const response = await axios.post("http://localhost:5000/api/add/item", { name: name }); setname(""); + setItems((prv)=>[...prv,response.data.item]) } catch (error) { // Handle errors, e.g., show an error message to the user console.error("Error:", error);