I’m doing a simple fetch on an internal page (like a product page), using a slug (like ‘my-product’) in the body, and it stopped working properly.
By debuggin it with the help of postman, making the precise same request on Postman leads to a right behavior and response, which is server properly by the endpoint POST api/kondos/findBy , that looks like this:
On postman the request looks like this:
But the same request using fetch, on a server side page on my Nextjs app, is looking like this:
export async function getKondoBySlug(slug: string) {
try {
const body = { slug };
const response = await fetch(`${apiUrl}/kondo/findBy`, {
method: "post",
cache: "no-store",
mode: "cors",
headers: {
//"Content-Type": "application/json",
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
},
body: JSON.stringify(body)
});
return await response.json();
} catch (error) {
console.log('FETCH ERROR', error);
}
}
And this function it’s being propely called on my page at: /src/app/(singles)/(default)/single/[[..slug]]/page.tsx , like this:
By debugging everything, I understand that the request is being wrongly received by the api endpoint GET api/kondos/findOne, that looks like this:
How come the same identical requests are received by different endpoints in the api ?