question

jinkysab avatar image
0 Likes"
jinkysab asked ·

Axios request. blocked by CORS policy: No 'Access-Control-Allow-Origin'

Hi,

I have a node (serverless) app with a React front end. I'm trying to make an Axios request to the eBay finding service:


let url = "http://svcs.ebay.com/services/search/FindingService/v1";;

url += "?GLOBAL-ID=EBAY-US";

url += "&keywords=hi";

url += "&OPERATION-NAME=findItemsByKeywords";

url += "&paginationInput.entriesPerPage=6";

url += "&paginationInput.pageNumber=1";

url += "&RESPONSE-DATA-FORMAT=json";

url += "&SECURITY-APPNAME=MYAPPNAME";

url += "&SERVICE-NAME=FindingService";

url += "&SERVICE-VERSION=1.12.0";

console.log(url);

axios

.get(url)

.then((result) => {

console.log(result);

this.setState({

data: result.data,

loading: false,

error: false,

});

})

.catch((error) => {

console.error("error: ", error);

this.setState({

error: `${error}`,

loading: false,

})


However console returns an error `Access to XMLHttpRequest at 'http://svcs.ebay.com/services/search/FindingService/v1?GLOBAL-ID=EBAY-US&keywords=hi&OPERATION-NAME=findItemsByKeywords&paginationInput.entriesPerPage=6&paginationInput.pageNumber=1&RESPONSE-DATA-FORMAT=json&SECURITY-APPNAME=<MYAPP>&SERVICE-NAME=FindingService&SERVICE-VERSION=1.12.0' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

However when I click on the link in console that console.log returns from the above code I get the JSON loaded into the browser.


Can anyone advise what the solution to this might be or have a pattern in node for making such requests that they can share?

finding apijavascriptcors
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.