I have developed a custom backend api for my expo app and when i try to call it on press of the button like the following:
const handleConfirmOrder = async () => {
const accessToken = '';
const products = [
{ productId: 1, quantity: 2 },
];
console.log("Sending", products)
fetch('http://10.0.0.133:8080/api/v1/order', { // Replace with your actual API URL
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
body: JSON.stringify({ products })
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch(error => {
console.error('Error:', error);
});
};
When this is called, nothing happens for a minute or so, then it prints out:
Error: [TypeError: Network request failed]
When i run the exact same request in postman with the same access token I get something, it seems the request doesn’t reach the backend. My expo is on localhost, the same as my api