Cross Domain Ajax Call in Atom Shell

前端 未结 3 1173
小蘑菇
小蘑菇 2021-02-08 02:48

We are working with Atom Shell (Currently known as electron) to wrap a web application as desktop app and having trouble making cross domain ajax calls due to CORS restriction.

3条回答
  •  执念已碎
    2021-02-08 03:01

    There are two problems here

    CORS restrictions, which prevent the client from initiating a request, and the Access-Control-Allow-Origin header which is set by the server.

    The first problem is solved as mentioned by setting the web-security options on the Browser-window object.

    "webPreferences" : {
        "webSecurity" : false
    },
    

    The second issue whereby Electron actually sends 'file://' as the value of the Origin in the request does not have a solution as far as I can tell. Your options are to allow 'file://' or '*' in the Access-Control-Allow-Origin header (server side).

    I have actually requested that setting the origin on requests be allowed but I suspect it will not get much traction.

提交回复
热议问题