I have a Laravel application that uses Inertia and React as the front end. Recently I was getting a CORS error. Basically I was trying to use Shopify’s API to connect a user’s store and retrieve their products by using a Sales channel app I created. When I try to use axios.post
from React to front end and then post to Shopify from there to receive access tokens and such I was always getting a CORS blocked because No access control header. This happened from the Shopify end as well when I tried to post from Shopify to my Laravel app using fetch
.
But then when I finally tried using the approach below everything worked perfectly. Can someone please explain why? What’s the difference between using Axios or fetch
and new Promise
in this case?
let myPromise = new Promise((resolve, reject) => {
resolve(url);
reject("Error");
});
myPromise.then(
function (result) {
return ({
success: true
})
},
function (error) {
console.error("ERROR::", error);
},
);
3