export const getServerSideProps = async () => {
const res = await axios.get('http://localhost:3000/api/products');
return {
props: {
kebabList: res.data
}
}
};
// get all the products
if (method === "GET") {
try {
const products = await Product.find();
res.status(200).json(products);
} catch (err) {
res.status(500).json(err);
}
}
When I first load the app it is showing this error Server Error Error: Request failed with status code 500
If I reload again then it works fine but after deploying on vercel the error is permanent
/api/productsan internal API route? If so, you shouldn't be fetching data from it insidegetServerSideProps. You should move the logic that's in the API route intogetServerSidePropsinstead. See Internal API fetch with getServerSideProps? (Next.js).