I am trying to fetch a list of blog posts from my Strapi backend and I’m getting a “Error: fetch failed” error. I’ve tried every solution I could find online and none has worked.
Below is the code of blog/page.tsx
page
import React from 'react'
async function getPosts(){
const baseURL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:1337";
const path = "/api/blog-posts";
const url = new URL(path, baseURL);
const res = await fetch(url);
if(!res.ok) throw new Error("Failed to fetch blog posts");
const data = await res.json();
console.log(data);
return data;
}
async function BlogPage() {
const blogPosts = await getPosts();
console.log(blogPosts);
return (
<div>BlogPage</div>
)
}
export default BlogPage
Is this related to Strapi 5 or am I missing something?
This topic has been created from a Discord post (1299205931313397931) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord