here I want to make a post method on API but when I call the function it posts to the wrong path of API
here is my script for the post
//Creating Order
const createOrder = async (data) => {
try {
const res = await axios.post(
`${process.env.API_ROOT}/api/orders` ||
`${process.env.LOCAL_URL}/api/orders`,
data
);
if (res.status === 201) {
router.push(`/api/orders/${res.data._id}`);
dispatch(reset());
}
} catch (err) {
console.log(err);
}
};
I call that function when approve from Paypal and using the order button, but when I press the button
the URL API path change to something ${process.env.API_ROOT}/undefined/api/orders
or ${process.env.LOCAL_URL}/undefined/api/orders
what cause this problem ?
but when im using something like its working
//Creating Order
const createOrder = async (data) => {
try {
const res = await axios.post(`/api/orders`,data); <===== its working
if (res.status === 201) {
router.push(`/api/orders/${res.data._id}`);
dispatch(reset());
}
} catch (err) {
console.log(err);
}
};