If you're using static exports in Next.js, it's important to note that certain features are not supported. For instance, dynamic server functions and internationalized routing do not integrate with static exports as they do not leverage the Next.js routing layer.
When you're using static exports, Next.js generates an HTML file per route. This can be configured in your next.config.js file. Here's an example:
const nextConfig = {
output: 'export',
}
module.exports = nextConfig
After running next build, Next.js will produce an out folder which contains the HTML/CSS/JS assets for your application.
However, if you're trying to fetch data from an external API, you should be able to do so without the fetch request being redirected to an internal URL. The fetch request should look something like this:
export default async function Page() {
const res = await fetch('<https://api.example.com/...'>)
const data = await res.json()
return <main>...</main>
}
In this example, <https://api.example.com/...> should be replaced with the URL of the external API you're trying to fetch data from.
If you're still experiencing issues, it might be due to the configuration of your server or hosting environment. Next.js static exports can be deployed and hosted on any web server that can serve HTML/CSS/JS static assets, including tools like AWS S3, Nginx, or Apache. You might need to check the configuration of your server or hosting environment to ensure that it's not redirecting fetch requests to an internal URL.