Playback filters are tempting, but when they don't work properly, as you noticed, magic is not so easy to track.
I prefer to use something like this:
implicit class RichResult (result: Result) { def enableCors = result.withHeaders( "Access-Control-Allow-Origin" -> "*" , "Access-Control-Allow-Methods" -> "OPTIONS, GET, POST, PUT, DELETE, HEAD" // OPTIONS for pre-flight , "Access-Control-Allow-Headers" -> "Accept, Content-Type, Origin, X-Json, X-Prototype-Version, X-Requested-With" //, "X-My-NonStd-Option" , "Access-Control-Allow-Credentials" -> "true" ) }
Then you can easily call it in your answer like this:
Ok(Json.obj("ok" -> "1")).enableCors
Itβs easy to understand, it can only be placed where you want to enable CORS, and itβs very easy to debug!
B faust
source share