Solved this:
All API responses from the server must contain the header: "Access-Control-Allow-Origin", "*". We need to write a wrapper for all responses to actions.
In Global.java
import java.net.URL; import play.*; import play.libs.F.Promise; import play.mvc.Action; import play.mvc.Http; import play.mvc.Result; public class Global extends GlobalSettings {
Server requests, such as POST, PUT, precede the request before the server before the main request. The response to these pre-flight requests should contain the following headers:
Access-Control-Allow-Origin, Allow, Access-Control-Allow-Methods, POST, GET, PUT, DELETE, OPTIONS, Access-Control-Allow-Headers, Origin , X-Requested-With, Content-Type, Accept, Referer, User-Agent "
In routes add:
OPTIONS /*all controllers.Application.preflight(all)
In the Coltroller app:
package controllers; import play.mvc.*; public class Application extends Controller { public static Result preflight(String all) { response().setHeader("Access-Control-Allow-Origin", "*"); response().setHeader("Allow", "*"); response().setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS"); response().setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent"); return ok(); } }
PS: With this approach, I did not need to create a scala filter for this.