fetch fails in page's load function when rendered on the server
I'm trying to fetch data from my strapi cms which runs locally on localhost in the load function. When i navigate to this URL from a different page (so when the page is clien rendered) it works, however upon refresh it throws an error:
​
fetch failed TypeError: fetch failed at Object.processResponse (C:\Users\Michał\Documents\VSCode\fraudhltv\node_modules\undici\lib\fetch\index.js:199:23) at C:\Users\Michał\Documents\VSCode\fraudhltv\node_modules\undici\lib\fetch\index.js:928:38 at node:internal/process/task_queues:140:7 at AsyncResource.runInAsyncScope (node:async_hooks:202:9) at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
​
\+page.js which loads the data:
export async function load({ params, fetch }) { let res = await fetch('http://localhost:1337/api/posts?populate=*'); let data = await res.json(); let news = data.data.map((el) => el.attributes); return news[params.id]; }
Any help with this? I can't figure out anything other than that fetching a different url works and I don't get a fetch failed error