Error [TypeError]: fetch failed in nextjs middleware.
Unanswered
Rainbow trout posted this in #help-forum
Rainbow troutOP
Hello, So i have a logic that fetches payment links and then redirects the user to it but that's fetched, however nextjs middleware is throwing me errors.
I have also checked for anything if i am lacking such a wrong request method and everything else .
No missing values
Correct headers, methods, body
Works when using a http client, but not working with
I have also checked for anything if i am lacking such a wrong request method and everything else .
No missing values
Correct headers, methods, body
Works when using a http client, but not working with
fetch in middleware5 Replies
Rainbow troutOP
switch (params.get("method")) {
case "PAYPAL": {
if (!params.has("planId")) return NextResponse.error();
console.log(params.get("userId"));
console.log(params.get("planId"));
const response = await fetch(
`http://localhost:3001/api/v1/payments/checkout?method=PAYPAL&uuid=${params.get(
"userId"
)}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
plan_id: params.get("planId"),
}),
}
);
if (!response.ok) return NextResponse.error();
const { url } = await response.json();
return NextResponse.redirect(url);
}works with thunderclient a http client
Rainbow troutOP
