'UNEXPECTED END OF JSON INPUT from querying data from headless cms Nextjs
here is my code for getting data from a graphql query from a headless CMS. It seems though that even though the query is being fetched without error, it creates the "UNEXPECTED END OF JSON INPUT". Occurs when parsing into JSON so I can pass the data to my page.
const URL = process.env.STRAPIBASEURL;
export async function getStaticProps(context) {
const fetchParams = {
method: "posts",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
query: `{
blogposts{
title
content
slug
img{
url
}
}
}`,
}),
};
const res = await fetch(`${URL}/graphql`, fetchParams);
const data = await res.json();
return {
props: data,
};
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
