Deadly CORS when http://localhost is the origin

后端 未结 9 1313
迷失自我
迷失自我 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:21

    Per @Beau's answer, Chrome does not support localhost CORS requests, and there is unlikely any change in this direction.

    I use the Allow-Control-Allow-Origin: * Chrome Extension to go around this issue. The extension will add the necessary HTTP Headers for CORS:

    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: "GET, PUT, POST, DELETE, HEAD, OPTIONS"
    Access-Control-Expose-Headers: 
    

    The source code is published on Github.

    Note that the extension filter all URLs by default. This may break some websites (for example: Dropbox). I have changed it to filter only localhost URLs with the following URL filter

    *://localhost:*/*
    

提交回复
热议问题