Deadly CORS when http://localhost is the origin

后端 未结 9 1311
迷失自我
迷失自我 2020-11-22 00:54

I am stuck with this CORS problem, even though I set the server (nginx/node.js) with the appropriate headers.

I can see in Chrome Network pane -> Response Headers:

9条回答
  •  盖世英雄少女心
    2020-11-22 01:28

    Agreed! CORS should be enabled on the server-side to resolve the issue ground up. However...

    For me the case was:

    I desperately wanted to test my front-end(React/Angular/VUE) code locally with the REST API provided by the client with no access to the server config.

    Just for testing

    After trying all the steps above that didn't work I was forced to disable web security and site isolation trials on chrome along with specifying the user data directory(tried skipping this, didn't work).

    For Windows

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

    Disable web security and site isolation trials

    chrome.exe  --disable-site-isolation-trials --disable-web-security --user-data-dir="PATH_TO_PROJECT_DIRECTORY"
    

    This finally worked! Hope this helps!

提交回复
热议问题