I have a problem with getStaticProps in NextJS, i try to load specialists from API Route, but I get an error.
export const getStaticProps = async () => {
const specialists = await loadSpecialists();
return {
props: { specialists },
};
};
export const loadSpecialists = async () => {
const response = await fetch('/api/specialists.js');
const data = await response.json();
return data;
};
if (req.method === 'GET') {
const specialists = await database
.collection('specialists')
.find()
.toArray();
res.status(200).json({ specialists });
}
I tried client-side rendering with useEffect and this works, but i need to prerender this page.