Setup CORS on Java Playframework 2.4.x + AngularJS

一世执手 提交于 2020-01-04 14:36:27

问题


I am trying to setup CORS in java playframework 2.4.x withouth success. My front-end app is using AngularJS 1.3.x.

I implemented the Filters class as per documentation but my preflights OPTIONS requests from AngularJS fail without apparent reason.

This is my application.conf values regarding the filter:

NOTE: I edited the domain names (I am not the owner of example.com) ;)

...
play.filters.cors {
    allowedOrigins = ["http://example.com", "http://beta.example.com", "http://example.com/beta"]
    allowedHttpMethods = ["GET", "POST", "PUT", "OPTIONS", "DELETE"]
    allowedHttpHeaders = ["Accept", "Content-type"]
    preflightMaxAge = 3 days
}
...

My play application is hosted in a separate server from the front-end: I essentially have a sub-directory on my main hosting containing the Angular app and a subdomain pointing to the play server.

Any ideas/suggestions on where I should investigate?


回答1:


After 3 days struggling on this I finally understood what was the problem. Apparently a module of Cisco AnyConnect VPN was blocking all the OPTIONS preflight requests.

Nothing related to Play or AngularJS.

Here's a the link from where I found the solution: http://www.bennadel.com/blog/2559-cisco-anyconnect-vpn-client-may-block-cors-ajax-options-requests.htm

It was enough just to uninstall the client and boom! Everything was working again!

Posting as reference for others that might have the same problem.

Best, E.



来源:https://stackoverflow.com/questions/31292029/setup-cors-on-java-playframework-2-4-x-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!