play framework cors跨域

接着上一篇的play framework 文件上传
、作为一个web项目、cors是一个基本功能、用于防跨站请求攻击的。

使用教程

添加依赖

libraryDependencies += filters

application.conf 配置

play.http {
  filters = filters.CorsFilter
}
play.filters {
  enabled += "play.filters.cors.CORSFilter"
  cors {
  
    # Filter paths by a whitelist of path prefixes
    pathPrefixes = ["/"]

    # The allowed origins. If null, all origins are allowed.
    allowedOrigins = null

//    allowedHttpHeaders = ["Accept"]

//    preflightMaxAge = 3 days

    # The allowed HTTP methods. If null, all methods are allowed
    allowedHttpMethods = ["GET", "POST", "OPTIONS"]
  }
}

所有请求默认禁止跨域、如果允许则在routes url上添加 + nocsrf

+ nocsrf
POST     /file/upload                 controllers.FileController.upload

最后

play framework真的很好用、添加代码动态编译加载。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。