Reputation: 1370
I have two apps:
The webpack app makes a POST request to the Play app
$.ajax({
url: 'http://localhost:9000/users',
data: JSON.stringify(data),
dataType: 'json',
method: 'POST'
})
To which the Play app responds with
Failed to load http://localhost:9000/users: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
Only when I explicitly set the header in the Play app with
def create = Action {
Ok("stuff").withHeaders(
"Access-Control-Allow-Origin" -> "http://localhost:3000"
)
}
does the request go through without error.
My question is: why doesn't Play set this header automatically as the docs seem to suggest? My application.conf
is an empty file.
Upvotes: 5
Views: 5771
Reputation: 1370
The CORS filter isn't enabled by default. Adding
play.filters.enabled += play.filters.cors.CORSFilter
to application.conf solves this issue
Upvotes: 9