Allow Access-Control-Allow-Origin header using HTML5 fetch API

前端 未结 6 1117
广开言路
广开言路 2020-12-08 01:57

I am using HTML5 fetch API.

var request = new Request(\'https://davidwalsh.name/demo/arsenal.json\');

fetch(request).         


        
6条回答
  •  悲&欢浪女
    2020-12-08 02:22

    This worked for me :

    npm install -g local-cors-proxy
    

    API endpoint that we want to request that has CORS issues:

    https://www.yourdomain.com/test/list
    

    Start Proxy:

    lcp --proxyUrl https://www.yourdomain.com
    
     Proxy Active 
    
     Proxy Url: http://www.yourdomain.com:28080
     Proxy Partial: proxy
     PORT: 8010
    

    Then in your client code, new API endpoint:

    http://localhost:8010/proxy/test/list
    

    End result will be a request to https://www.yourdomain.ie/test/list without the CORS issues!

提交回复
热议问题