Hello Community!
I have deployed my app in Vercel and I am struggling to fetch my data from MongoDB (which is working locally).
I really think it's something simple but after reading the docs and checking some examples I can't tell what's the issue.
The following code contains the problematic data fetch (I assume that fixing this will resolve the other case where data fetching doesn't work):
`// On mount fetch the list of all Todos from the Mongo database
useEffect(() => {
const controller = new AbortController();
const signal = controller.signal;
async function getTodos() {
const options = {
method: "GET",
url: "/api/todos",
signal,
};
try {
const response = await axios.request(options);
if (response.statusText !== "OK") {
throw new Error("Failed to fetch Todos");
}
const todos = response.data.todos;
// Set the state so the list can be displayed to the user
setTodosArray([...todos]);
} catch (error) {
console.log(error);
}
}
getTodos();
return () => {
// Cleanup function
controller.abort();
};
}, []);`
In Vercel it throws the "Failed to fetch Todos" error that is thrown if the response status is not OK. I also see that the Integration is properly set in Vercel and the MONGODB_URI env variable was automatically added when the setup was complete.
Thank you for the assistance in advance!