How to solve CORS error when using fake API?

Viewed 51

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))

2 Answers

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

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

Related