Answer the question
In order to leave comments, you need to log in
Why does NEXT JS throw FetchError when using SSR?
next js packaged in Docker
frontend:
build: ./frontend
nginx:
build: ./nginx
volumes:
- ./backend/static:/backend/static
- ./backend/media:/backend/media
ports:
- 80:80
export async function getServerSideProps() {
const response = await fetch(`${process.env.API_URL}/categories/`);
const categories = await response.json();
return {
props: { categories },
};
}
Answer the question
In order to leave comments, you need to log in
https://nextjs.org/docs/basic-features/data-fetch...
Note: You should not use fetch() to call an API route in getServerSideProps. Instead, directly import the logic used inside your API route. You may need to slightly refactor your code for this approach.
Fetching from an external API is fine!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question