CORS issue with Vue.js

后端 未结 5 729
鱼传尺愫
鱼传尺愫 2020-12-03 03:37

I\'m using:

  • Vue 2.0.3
  • vue-router 2.0.1
  • vuex 0.8.2
  • vue-resource 0.7.0

And after trying to login to my page when using

5条回答
  •  自闭症患者
    2020-12-03 04:19

    While you can add Access-Control-Allow-Origin: * to your server response (in this case IIS) but this is very much advised against.

    What's happening here is that your client is http://localhost and it is trying to access https://mywebsite/api/ which means they're not from the same origin

    If you add Access-Control-Allow-Origin: * you will be allowing the entire world to hit your API endpoint.

    I'd suggest making your access control server headers Access-Control-Allow-Origin: *.mysite and make a vhost for your localhost to use dev.mysite or similar.

    This will allow your "localhost" to access your API without issues.

    You could also add localhost to a whitelist, but this is also not without its own security implications, and it doesn't work everywhere anyway.

    So, in short, make a vhost for your localhost that's in the same domain as your REST service and your issue should be resolved.

    Once you go live you should remove the *.mysite part and use as specific a domain as possible on your whitelist.

    Good luck!

提交回复
热议问题