[ i have question in the end]
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
App.jsx:18 Error fetching todos: SyntaxError: Unexpected token ‘P’, “Proxy erro”… is not valid JSON
this is the error statement
what I understand is that its a internal server error in my code
this is the route.js
const express = require("express")
const router = express.Router();
// // get todo
router.get("/todos",(req,res)=>{
res.status(200).json({mssg:"GET REQUEST TO /api/todos"})
});
// post todo
router.post("/todos",(req,res)=>{
res.status(201).json({mssg:"GET REQUEST TO /api/todos"})
});
//delete todo
router.delete("/todos/:id",(req,res)=>
{
res.status(200).json({mssg:"DELETE REQUEST TO /api/todos/:id"});
});
//put todoo
router.put("/todos/:id",(req,res)=>{
res.status(200).json({mssg:"PUT REQUEST TO /api/todos/:id"});
});
module.exports =router;
this is part of client folder
import { useEffect } from "react";
export default function App() {
useEffect(()=> {
async function getTodos() {
const res = await fetch("/api/todos");
const todos = await res.json();
console.log(todos);
}
getTodos();
},[])
return (
<main className="container">
<h1>The to-do</h1>
</main>
);
}
and we added a proxy in packages.json to bypass the coros policy and shorten the whole http link
to /api/todos to allow it to change the port
any thing more to add
QUESTIONS
- why am i getting a p token error
2)if there error is due to lack of fundamental knowledge please enlighten me
i tried the above while following a course on yt.