ebay-node-api icon indicating copy to clipboard operation
ebay-node-api copied to clipboard

Running into CORS error

Open Anand-Issac opened this issue 5 years ago • 15 comments

from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I was wondering how to fix this error for the Search by keyword API

Anand-Issac avatar May 13 '20 22:05 Anand-Issac

@Anand-Issac Kindly provide me more context how are you trying to access the library. Are you using in server-side or client-side using AJAX calls ?.

If server side, are u using express js ?.

pajaydev avatar May 14 '20 02:05 pajaydev

I was using an AJAX call, the fetch API in react to use the ebay Finding API. I set a proxy in my package.json to solve the CORS issue but now I face a problem that after I deploy the application using Firebase Hosting, the API call returns an index.html response instead of the JSON response I got in my localhost server. I was wondering why this was so and if there is any solution to this ?

Anand-Issac avatar May 16 '20 06:05 Anand-Issac

@Anand-Issac Ohh that's weird. Is there any URL or github link, I can check ?.

pajaydev avatar May 16 '20 22:05 pajaydev

@pajaydev Yes sure: https://github.com/Anand-Issac/shopping-cart

Anand-Issac avatar May 16 '20 23:05 Anand-Issac

Cool. I will take a look

pajaydev avatar May 16 '20 23:05 pajaydev

@pajaydev Hey man. Did you figure out the problem yet?

Anand-Issac avatar May 18 '20 02:05 Anand-Issac

@Anand-Issac Sorry was stuck in some other things, will look it up tonight

pajaydev avatar May 18 '20 03:05 pajaydev

@Anand-Issac I can see its working fine in local (both read and write data from firebase).
if I am not wrong, you are facing issue after deploying. Kindly share me the URL where you have deployed the code.

Screen Shot 2020-05-17 at 8 37 32 PM

pajaydev avatar May 18 '20 03:05 pajaydev

@pajaydev Thanks for the help bro

https://shopping-cart-b4473.web.app/

Anand-Issac avatar May 18 '20 05:05 Anand-Issac

If you try to request ebay API now on deployed app it will return a HTML file (my index.html) instead of the proper JSON response. It still says Status 200 though ... I'm not exactly sure why this happens

Anand-Issac avatar May 18 '20 05:05 Anand-Issac

@Anand-Issac sure I will take a look. Thanks

pajaydev avatar May 19 '20 05:05 pajaydev

@Anand-Issac I made a simple proxy using express JS to call this library.

Kindly take a look at it.

https://gist.github.com/pajaydev/b10b4d29bae85b441954d298a9e0d2c3

I would do like this to set up a simple proxy. Let me know if you face any issue. Hope it helps.

pajaydev avatar May 20 '20 05:05 pajaydev

Let me give it a try

On Wed., May 20, 2020, 1:10 a.m. Ajaykumar, [email protected] wrote:

@Anand-Issac https://github.com/Anand-Issac I made a simple proxy using express JS to call this library.

Kindly take a look at it.

https://gist.github.com/pajaydev/b10b4d29bae85b441954d298a9e0d2c3

I would do like this to set up a simple proxy. Let me know if you face any issue. Hope it helps.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pajaydev/ebay-node-api/issues/91#issuecomment-631240183, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKCWR2I2QLJZ25COH5RBPOLRSNQ6BANCNFSM4NAEXGLA .

Anand-Issac avatar May 20 '20 14:05 Anand-Issac

Hey @pajaydev Sorry for the long response time. I had a lot of school work to do.

Okay so I implemented your solution. The problem is. When I run in my local server the response says 200 but it returns me my own HTML page as a response instead of the JSON data I would like

Can you please take a look? https://github.com/Anand-Issac/shopping-cart

Here is the repo .

Thanks

Anand-Issac avatar May 24 '20 17:05 Anand-Issac

I will take a look

pajaydev avatar May 27 '20 08:05 pajaydev