Playframework 播放框架CORS请求
我有两个应用程序:Playframework 播放框架CORS请求,playframework,cors,Playframework,Cors,我有两个应用程序: 播放在本地主机上运行的2.6.7应用程序:9000 在本地主机上运行的网页包开发服务器:3000 网页包应用程序向Play应用程序发出POST请求 $.ajax({ url: 'http://localhost:9000/users', data: JSON.stringify(data), dataType: 'json', method: 'POST' }) Play应用程序对其作出响应 Failed to load http://localhost:9
$.ajax({
url: 'http://localhost:9000/users',
data: JSON.stringify(data),
dataType: 'json',
method: 'POST'
})
Play应用程序对其作出响应
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.
仅当我在Play应用程序中使用
def create = Action {
Ok("stuff").withHeaders(
"Access-Control-Allow-Origin" -> "http://localhost:3000"
)
}
请求是否顺利通过
我的问题是:为什么Play不按照玩家的建议自动设置这个标题?我的
application.conf
是一个空文件。默认情况下不启用CORS筛选器。添加
play.filters.enabled += play.filters.cors.CORSFilter
to application.conf解决了这个问题下面是一个工作示例。