Fetch request in server action not working

I have a react hook form with 'use client' In my onsubmit I want to do a post request to my other backend (for testing on localhost:5001, but Nextjs always gives an error, Do I need to do things differently to make it work or is such fetch only possible in client side?
export async function sendContactAction(data: any) {
console.log(data);
const response = await fetch('http://127.0.0.1:5001/contact', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
}
export async function sendContactAction(data: any) {
console.log(data);
const response = await fetch('http://127.0.0.1:5001/contact', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
}
1 Reply
Thimo_o
Thimo_o13mo ago
I already use the usetransition hook to send the data to the action and it arrives correctly