james emanon
james emanon

Reputation: 11837

Next.js api route resolving to 404 BUT it works fine via postman

Please see the attachment, it shows the folder structure, and the "404" error I am getting when I try to fetch the api. When I run the same api via postman it works fine. But within the nextjs ecosystem, I get a 404. Is there a config issue perhaps I am missing.

enter image description here

Upvotes: 2

Views: 1144

Answers (1)

Thanh
Thanh

Reputation: 8624

From the doc https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering

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!

Upvotes: 2

Related Questions