diff --git a/app/AppLoader.scala b/app/AppLoader.scala index dc7bf56778..3d4a368e35 100644 --- a/app/AppLoader.scala +++ b/app/AppLoader.scala @@ -3,6 +3,8 @@ import play.api.inject.ApplicationLifecycle final class LilaLoader extends ApplicationLoader { + println("LilaLoader") + // def load(context: Context) = { // val application = new GuiceApplicationBuilder( // environment = context.environment, @@ -13,11 +15,12 @@ final class LilaLoader extends ApplicationLoader { // } def load(context: ApplicationLoader.Context): Application = { + println("LilaLoader.load") val components = new LilaComponents(context) val app = components.application old.play.Env.start(app) - startKamon(context.lifecycle) - lila.app.Env.current + // startKamon(context.lifecycle) + // lila.app.Env.current app } @@ -30,5 +33,7 @@ final class LilaLoader extends ApplicationLoader { final class LilaComponents(context: ApplicationLoader.Context) extends BuiltInComponentsFromContext(context) { + def router = _root_.router.Routes + def httpFilters = Nil } diff --git a/app/controllers/Irwin.scala b/app/controllers/Irwin.scala index cec0bd1896..af8c41ea00 100644 --- a/app/controllers/Irwin.scala +++ b/app/controllers/Irwin.scala @@ -19,7 +19,7 @@ object Irwin extends LilaController { def saveReport = OpenBody(parse.json) { implicit ctx => ModExternalBot { - UserRepo.irwin.flatten("Missing irwin user") flatMap { irwin => + UserRepo.irwin err "Missing irwin user" flatMap { irwin => ctx.body.body.validate[lila.irwin.IrwinReport].fold( err => fuccess(BadRequest(err.toString)), report => Env.irwin.api.reports.insert(report) inject Ok diff --git a/app/controllers/LilaController.scala b/app/controllers/LilaController.scala index 3c0eba3099..feb1451d75 100644 --- a/app/controllers/LilaController.scala +++ b/app/controllers/LilaController.scala @@ -27,8 +27,6 @@ private[controllers] trait LilaController protected implicit val LilaResultZero = Zero.instance[Result](Results.NotFound) - protected implicit val LilaHtmlMonoid = lila.app.templating.Environment.LilaHtmlMonoid - protected implicit final class LilaPimpedResult(result: Result) { def fuccess = scala.concurrent.Future successful result } diff --git a/app/controllers/LilaSocket.scala b/app/controllers/LilaSocket.scala index 5dcf9c7bf7..0b91c70a94 100644 --- a/app/controllers/LilaSocket.scala +++ b/app/controllers/LilaSocket.scala @@ -2,7 +2,7 @@ package controllers import play.api.libs.iteratee._ import play.api.mvc._ -import play.api.mvc.WebSocket.FrameFormatter +// import play.api.mvc.WebSocket.FrameFormatter import lila.api.Context import lila.app._ @@ -14,60 +14,68 @@ trait LilaSocket { self: LilaController => private val notFoundResponse = NotFound(jsonError("socket resource not found")) - protected def SocketEither[A: FrameFormatter](f: Context => Fu[Either[Result, Pipe[A]]]) = - WebSocket.tryAccept[A] { req => - SocketCSRF(req) { - reqToCtx(req) flatMap f - } - } + // protected def SocketEither[A: FrameFormatter](f: Context => Fu[Either[Result, Pipe[A]]]) = + protected def SocketEither[A](f: Context => Fu[Either[Result, Pipe[A]]]) = + TODO + // WebSocket.tryAccept[A] { req => + // SocketCSRF(req) { + // reqToCtx(req) flatMap f + // } + // } - protected def Socket[A: FrameFormatter](f: Context => Fu[Pipe[A]]) = - SocketEither[A] { ctx => - f(ctx) map scala.util.Right.apply - } + // protected def Socket[A: FrameFormatter](f: Context => Fu[Pipe[A]]) = + protected def Socket[A](f: Context => Fu[Pipe[A]]) = + TODO + // SocketEither[A] { ctx => + // f(ctx) map scala.util.Right.apply + // } - protected def SocketOption[A: FrameFormatter](f: Context => Fu[Option[Pipe[A]]]) = - SocketEither[A] { ctx => - f(ctx).map(_ toRight notFoundResponse) - } + // protected def SocketOption[A: FrameFormatter](f: Context => Fu[Option[Pipe[A]]]) = + protected def SocketOption[A](f: Context => Fu[Option[Pipe[A]]]) = + TODO + // SocketEither[A] { ctx => + // f(ctx).map(_ toRight notFoundResponse) + // } - protected def SocketOptionLimited[A: FrameFormatter](limiter: lila.memo.RateLimit[IpAddress], name: String)(f: Context => Fu[Option[Pipe[A]]]) = - rateLimitedSocket[A](limiter, name) { ctx => - f(ctx).map(_ toRight notFoundResponse) - } + // protected def SocketOptionLimited[A: FrameFormatter](limiter: lila.memo.RateLimit[IpAddress], name: String)(f: Context => Fu[Option[Pipe[A]]]) = + protected def SocketOptionLimited[A](limiter: lila.memo.RateLimit[IpAddress], name: String)(f: Context => Fu[Option[Pipe[A]]]) = + TODO + // rateLimitedSocket[A](limiter, name) { ctx => + // f(ctx).map(_ toRight notFoundResponse) + // } - private type AcceptType[A] = Context => Fu[Either[Result, Pipe[A]]] + // private type AcceptType[A] = Context => Fu[Either[Result, Pipe[A]]] - private val rateLimitLogger = lila.log("ratelimit") + // private val rateLimitLogger = lila.log("ratelimit") - private def rateLimitedSocket[A: FrameFormatter](limiter: lila.memo.RateLimit[IpAddress], name: String)(f: AcceptType[A]): WebSocket[A, A] = - WebSocket[A, A] { req => - SocketCSRF(req) { - reqToCtx(req) flatMap { ctx => - val ip = HTTPRequest lastRemoteAddress req - def userInfo = { - val sri = get("sri", req) | "none" - val username = ctx.usernameOrAnon - s"user:$username sri:$sri" - } - f(ctx).map { resultOrSocket => - resultOrSocket.right.map { - case (readIn, writeOut) => (e, i) => { - writeOut |>> i - e &> Enumeratee.mapInput { in => - if (limiter(ip, 1)(true)) in - else { - rateLimitLogger.info(s"socket:$name socket close $ip $userInfo $in") - Input.EOF - } - } |>> readIn - } - } - } - } - } - } + // private def rateLimitedSocket[A: FrameFormatter](limiter: lila.memo.RateLimit[IpAddress], name: String)(f: AcceptType[A]): WebSocket[A, A] = + // WebSocket[A, A] { req => + // SocketCSRF(req) { + // reqToCtx(req) flatMap { ctx => + // val ip = HTTPRequest lastRemoteAddress req + // def userInfo = { + // val sri = get("sri", req) | "none" + // val username = ctx.usernameOrAnon + // s"user:$username sri:$sri" + // } + // f(ctx).map { resultOrSocket => + // resultOrSocket.right.map { + // case (readIn, writeOut) => (e, i) => { + // writeOut |>> i + // e &> Enumeratee.mapInput { in => + // if (limiter(ip, 1)(true)) in + // else { + // rateLimitLogger.info(s"socket:$name socket close $ip $userInfo $in") + // Input.EOF + // } + // } |>> readIn + // } + // } + // } + // } + // } + // } - private def SocketCSRF[A](req: RequestHeader)(f: => Fu[Either[Result, A]]): Fu[Either[Result, A]] = - if (csrfCheck(req)) f else csrfForbiddenResult map Left.apply + // private def SocketCSRF[A](req: RequestHeader)(f: => Fu[Either[Result, A]]): Fu[Either[Result, A]] = + // if (csrfCheck(req)) f else csrfForbiddenResult map Left.apply } diff --git a/app/controllers/Main.scala b/app/controllers/Main.scala index 900b3d9532..e282be56ac 100644 --- a/app/controllers/Main.scala +++ b/app/controllers/Main.scala @@ -41,9 +41,10 @@ object Main extends LilaController { } } - def apiWebsocket = WebSocket.tryAccept { req => - Env.site.apiSocketHandler.apply map Right.apply - } + def apiWebsocket = TODO + // WebSocket.tryAccept { req => + // Env.site.apiSocketHandler.apply map Right.apply + // } def captchaCheck(id: String) = Open { implicit ctx => Env.hub.actor.captcher ? ValidCaptcha(id, ~get("solution")) map { diff --git a/app/templating/Environment.scala b/app/templating/Environment.scala index f6268ad98e..a31feaa522 100644 --- a/app/templating/Environment.scala +++ b/app/templating/Environment.scala @@ -41,16 +41,11 @@ object Environment with SimulHelper with ChessgroundHelper { - implicit val LilaHtmlMonoid = scalaz.Monoid.instance[Html]( - (a, b) => Html(a.body + b.body), - LilaHtmlZero.zero - ) - type FormWithCaptcha = (play.api.data.Form[_], lila.common.Captcha) def netDomain = apiEnv.Net.Domain def netBaseUrl = apiEnv.Net.BaseUrl - val isGloballyCrawlable = apiEnv.Net.Crawlable + lazy val isGloballyCrawlable = apiEnv.Net.Crawlable def isProd = apiEnv.isProd diff --git a/app/templating/StringHelper.scala b/app/templating/StringHelper.scala index 21e40eaa5a..55c899380d 100644 --- a/app/templating/StringHelper.scala +++ b/app/templating/StringHelper.scala @@ -12,6 +12,11 @@ trait StringHelper { self: NumberHelper => implicit val LilaHtmlZero: Zero[Html] = Zero.instance(Html("")) + implicit val LilaHtmlMonoid = scalaz.Monoid.instance[Html]( + (a, b) => Html(a.body + b.body), + LilaHtmlZero.zero + ) + val slugify = lila.common.String.slugify _ def pluralize(s: String, n: Int) = s"$n $s${if (n > 1) "s" else ""}" diff --git a/build.sbt b/build.sbt index 547e763782..4f3907ebe6 100644 --- a/build.sbt +++ b/build.sbt @@ -8,8 +8,7 @@ import BuildSettings._ import Dependencies._ lazy val root = Project("lila", file(".")).dependsOn(api).aggregate(api) - .enablePlugins(PlayScala, PlayNettyServer, JavaAppPackaging) - .disablePlugins(PlayAkkaHttpServer) + .enablePlugins(PlayScala, JavaAppPackaging) .disablePlugins(PlayFilters) scalaVersion := globalScalaVersion diff --git a/conf/base.conf b/conf/base.conf index ce55f4fb97..84b0442268 100644 --- a/conf/base.conf +++ b/conf/base.conf @@ -17,8 +17,11 @@ net { } forcedev = false play { + application.loader = LilaLoader server { netty { + log.wire = true + transport = "jdk" # native for best perf; only on linux # The maximum length of the initial line. This effectively restricts the maximum length of a URL that the server will # accept, the initial line consists of the method (3-7 characters), the URL, and the HTTP version (8 characters), # including typical whitespace, the maximum URL length will be this number - 18. @@ -28,7 +31,6 @@ play { # number of cookies and size of cookie values. maxHeaderSize = 4096 # 8192 } - application.loader = LilaLoader } http { session { diff --git a/conf/logback.xml b/conf/logback.xml index 362aa30ce2..7f1ab740d7 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -1,16 +1,12 @@ - + - - INFO - %coloredLevel %logger{25} - %message%n%xException{10} - INFO ${application.home}/logs/all.log %date %-5level %logger{30} %message%n%xException{60} diff --git a/conf/prod-logger.xml b/conf/prod-logger.xml index 76e794bda0..5cfbc6b928 100644 --- a/conf/prod-logger.xml +++ b/conf/prod-logger.xml @@ -1,6 +1,6 @@ - + diff --git a/modules/common/src/main/GoodOldPlay.scala b/modules/common/src/main/GoodOldPlay.scala index 0c837c54cd..4fb4bfbc7b 100644 --- a/modules/common/src/main/GoodOldPlay.scala +++ b/modules/common/src/main/GoodOldPlay.scala @@ -7,7 +7,6 @@ import akka.actor.{ ActorSystem, Scheduler } import akka.stream.Materializer import play.api._ import play.api.ApplicationLoader.Context -import play.api.inject.guice.GuiceApplicationBuilder import play.api.inject.Injector import play.api.libs.ws.{ WSClient, StandaloneWSClient } import play.api.Mode @@ -21,11 +20,16 @@ import scala.concurrent.ExecutionContext */ object Env { + println("################# common Env") + private val _ref: AtomicReference[Application] = new AtomicReference[Application]() def start(app: Application) = _ref.set(app) - lazy val application: Application = Option(_ref.get()).get + lazy val application: Application = { + println("################# common Env application") + Option(_ref.get()).get + } lazy val actorSystem: ActorSystem = application.actorSystem lazy val materializer: Materializer = application.materializer lazy val configuration: Configuration = application.configuration