API response:
export const getCourses = (req, res) => {
const q = `SELECT c.*, u.id AS teacherId FROM courses AS c JOIN users AS u ON (u.id = c.teacherId)`;
db.query(q, (err, data) => {
if (err) return res.status(500).json(err);
return res.status(200).json(data);
});
};
Axios request function:
export const makeRequest = axios.create({
baseURL: "http://localhost:8800/api/",
withCredentials: true,
headers: [{ "Access-Control-Allow-Origin": origin, "access-control-allow-credentials": true }],
method: "GET",
url: "requisitions",
});
Front-end request (useQuery):
const { isLoading, error, data } = useQuery({
queryKey: ["courses"],
queryFn: () => makeRequest
.get("/courses")
.then((res) => {
return res.data;
}),
});
The error I am getting: GET http://localhost:8800/api/courses 404 (Not Found)
I tried to POST using Insomnia and I got the response. But here I am getting the error.
How can I solve this error?