0

I am using fake api and getting this well known "No 'Access-Control-Allow-Origin' header is present on the requested resource." I watched videos and read articles related to this problem but they are showing the solution while they are using their own server (express) and api but I am using a third party API then how I would set headers for it?

The errors:

Errors (although its so popular that have already seen it LOL))

E_net4
  • 27,810
  • 13
  • 101
  • 139
UnkownSomeone
  • 39
  • 1
  • 6
  • Is the FakeStoreAPI working? I tried going to it and I keep getting a gateway timeout. It's possible you are seeing CORS because the response is a 504 from Cloudflare without any cors headers. Maybe try waiting until the site is working again. – g0rb Sep 14 '22 at 07:05
  • @JaromandaX, the API request isn't returning a response from the normal FakeAPI site. Instead, it's returning a 504 error page from Cloudflare. This error page will not contain any CORS headers. Since the CORS headers don't exist on this Cloudflare error response, and you are doing a fetch request, the browser warns of a CORS issue. The real issue is that the FakeAPI is down. I'd look for an alternative fake API or wait until it's fixed. You could raise an issue on the Github: https://github.com/keikaavousi/fake-store-api/issues – g0rb Sep 14 '22 at 07:15
  • ahh, of course @g0rb - I hadn't considered that :p – Jaromanda X Sep 14 '22 at 07:52
  • @UnkownSomeone Looks like the FakeStoreAPI is back up? Is it working for you now? – g0rb Sep 14 '22 at 15:46
  • @g0rb yes, it is working now. – UnkownSomeone Sep 15 '22 at 04:11

2 Answers2

2

A temporary shortcut solution: You can use an extension for your browser to solve CORS error. Allow CORS: Access-Control-Allow-Origin enter image description here

Fahad Hussain
  • 121
  • 1
  • 2
1

If you are using google chrome, you can simply disable web security during your development:

  1. Open cmd

  2. Go to chrome.exe installation dir (C:\Program Files\Google\Chrome\Application is Default dir):

    cd C:\Program Files\Google\Chrome\Application

  3. Open chrome.exe with --disable-web-security argument:

    chrome.exe --disable-web-security

enter image description here

You can find more info for other OS here

amir_a14
  • 1,478
  • 10
  • 15
  • assumes 2 things ... OP is running windows (which you've sort of addressed with a link for some reason)... OP is using chrome – Jaromanda X Sep 14 '22 at 06:59