Skip to content

Commit

Permalink
finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
Luxshan2000 committed Sep 28, 2023
1 parent 75d11bc commit 0097ded
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}))
Expand Down
1 change: 1 addition & 0 deletions backend/src/controllers/addData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.addItem = async (req,res) =>{

console.log("Successfully meal added!")

res.json({status:"Success", item:newItem })


} catch(error){
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/AddItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0097ded

Please sign in to comment.