app compiles but crashes at runtime
parent
2578a4f384
commit
ebfeeb55aa
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 ""}"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
<configuration>
|
||||
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder><pattern>%coloredLevel %logger{25} - %message%n%xException{10}</pattern></encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ALL_FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO</level></filter>
|
||||
<file>${application.home}/logs/all.log</file>
|
||||
<encoder><pattern>%date %-5level %logger{30} %message%n%xException{60}</pattern></encoder>
|
||||
</appender>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<configuration>
|
||||
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />
|
||||
|
||||
<!-- STDOUT that accepts WARN and ERROR -->
|
||||
<!-- Exceptions yes, stacktraces no -->
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue