接著上一篇的play framework 文件上傳
师枣、作為一個(gè)web項(xiàng)目、cors是一個(gè)基本功能、用于防跨站請(qǐng)求攻擊的株婴。
使用教程
添加依賴
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"]
}
}
所有請(qǐng)求默認(rèn)禁止跨域、如果允許則在routes url上添加 + nocsrf
+ nocsrf
POST /file/upload controllers.FileController.upload
最后
play framework真的很好用暑认、添加代碼動(dòng)態(tài)編譯加載困介。