It´s giving this error when I click submit order and I don´t understand what is wrong , help pls
Erro ao enviar o pedido. Detalhes: <!DOCTYPE html>
Error
Cannot POST /orders
My frontend where I have the orders:
const submitOrder = async () => {
try {
// Calcula o total da encomenda
//const totalAmount = cartItems.reduce(
//(total, item) => total + item.price * item.quantity,
//0
// );
// Logs para verificar os dados enviados
console.log("Enviando pedido:", {
items: cartItems,
//total: totalAmount,
});
// Envia a requisição para o backend
const response = await fetch("http://localhost:3000/orders", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
items: cartItems,
//total: totalAmount,
}),
});
const responseBody = await response.text();
console.log("Resposta do servidor:", responseBody);
if (response.ok) {
alert("Pedido enviado com sucesso!");
setCartItems([]); // Limpa o carrinho
} else {
alert("Erro ao enviar o pedido. Detalhes: " + responseBody);
}
} catch (error) {
console.error("Erro ao enviar o pedido:", error);
}
};
image is part of the Backend, I´m struggling to add all here
New contributor
Patrícia Mendes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1