In the Next.JS documentation I read the following.
Note: You should not use fetch() to call an API route in getStaticProps. 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!
But if I'm not supposed to use the internal API then two questions arise.
- How can I handle POSTS? Should I handle POSTS / PUTS etc through the API but not GETS? That seems odd to me.
- If I also should not do 'internal POSTS etc' why is the API option there?
edit:
Hmm. I suppose one of the reasons is that when using getStaticProps, and compiling a static version of the site, @ compile time the API is potentially not running. But that could be easily solved by running the API at the same time. (Since GetStaticProps is not really relevant for interactive pages, so POST etc)
edit2:
Someone here also figure that out. Next.js - Error: only absolute urls are supported run export and sever separately and then you can do fetch in static props when needed. Then at least all stuff is in one place.