Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate CORS on my LOCAL machine?

Is it possible ti create a web site in IIS7 which somehow could look like it sits in a different domain, so that from one of this site's pages I can test Cross-Origin-Resource-Sharing calls to a WCF service in my local host?

like image 439
pencilCake Avatar asked Feb 20 '13 09:02

pencilCake


People also ask

How do you test CORS locally?

You can test it with any rest client like POSTMAN Rest Client, or simply you can check it from browser console - > Network tab -> in xhr filter - check the header for the particular request. you can check request and response.

How do I enable CORS on localhost?

1. Use the proxy setting in Create React App. "proxy": "https://cat-fact.herokuapp.com/", Now when you make an API request to https://localhost:3000/api/facts Create React App will proxy the API request to https://cat-fact.herokuapp.com/facts and the CORS error will be resolved.

Is it safe to allow CORS from localhost?

Having given the concept that CORS does not provide any additional security when talking about API access, this means that that allowing a particular domain like localhost does not make your API less secure.


1 Answers

You can add any domain names you like to your hosts file (%windir%\System32\Drivers\etc\hosts) and map those back to 127.0.0.1. Any requests to that domain will then be sent to your local machine.

Each domain name you add should be treated separately so far as CORS is concerned. If you're on a Windows Server SKU, you can even configure IIS to use multiple sites and configure it to examine host headers to determine which site responds to requests for each domain.

like image 52
Damien_The_Unbeliever Avatar answered Sep 28 '22 06:09

Damien_The_Unbeliever