问题
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