2019-12-06 09:39:42 -07:00
|
|
|
package lila.app
|
|
|
|
|
2019-12-26 18:28:17 -07:00
|
|
|
import akka.actor.CoordinatedShutdown
|
2019-12-05 08:46:00 -07:00
|
|
|
import com.softwaremill.macwire._
|
|
|
|
import play.api._
|
2019-12-26 18:28:17 -07:00
|
|
|
import play.api.libs.crypto.CookieSignerProvider
|
2020-09-07 08:10:56 -06:00
|
|
|
import play.api.libs.ws.StandaloneWSClient
|
2019-12-05 08:46:00 -07:00
|
|
|
import play.api.mvc._
|
2019-12-07 08:46:25 -07:00
|
|
|
import play.api.mvc.request._
|
2019-12-05 08:46:00 -07:00
|
|
|
import play.api.routing.Router
|
|
|
|
import router.Routes
|
2020-09-07 08:10:56 -06:00
|
|
|
import scala.annotation.nowarn
|
2019-12-05 08:46:00 -07:00
|
|
|
|
2019-12-06 09:39:42 -07:00
|
|
|
final class AppLoader extends ApplicationLoader {
|
2019-12-05 22:35:55 -07:00
|
|
|
def load(ctx: ApplicationLoader.Context): Application = new LilaComponents(ctx).application
|
2019-12-05 08:46:00 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 04:46:19 -06:00
|
|
|
final class LilaComponents(ctx: ApplicationLoader.Context) extends BuiltInComponentsFromContext(ctx) {
|
2019-12-05 08:46:00 -07:00
|
|
|
|
2020-11-25 14:10:47 -07:00
|
|
|
// https://www.scala-lang.org/api/2.13.4/scala/concurrent/ExecutionContext%24.html#global:scala.concurrent.ExecutionContextExecutor
|
|
|
|
implicit val ec: scala.concurrent.ExecutionContext =
|
|
|
|
scala.concurrent.ExecutionContext.getClass
|
|
|
|
.getDeclaredMethod("opportunistic")
|
|
|
|
.invoke(scala.concurrent.ExecutionContext)
|
|
|
|
.asInstanceOf[scala.concurrent.ExecutionContext]
|
|
|
|
|
2019-12-05 08:46:00 -07:00
|
|
|
LoggerConfigurator(ctx.environment.classLoader).foreach {
|
|
|
|
_.configure(ctx.environment, ctx.initialConfiguration, Map.empty)
|
|
|
|
}
|
2019-12-19 22:11:32 -07:00
|
|
|
|
|
|
|
lila.log("boot").info {
|
2020-06-06 07:51:03 -06:00
|
|
|
val java = System.getProperty("java.version")
|
2020-08-16 07:15:02 -06:00
|
|
|
val mem = Runtime.getRuntime.maxMemory() / 1024 / 1024
|
2020-06-06 07:51:03 -06:00
|
|
|
val appVersionCommit = ~configuration.getOptional[String]("app.version.commit")
|
|
|
|
val appVersionDate = ~configuration.getOptional[String]("app.version.date")
|
2020-08-16 06:48:46 -06:00
|
|
|
s"lila ${ctx.environment.mode} $appVersionCommit $appVersionDate / java $java, memory: ${mem}MB"
|
2019-12-19 22:11:32 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 08:46:00 -07:00
|
|
|
import _root_.controllers._
|
|
|
|
|
2019-12-07 08:46:25 -07:00
|
|
|
// we want to use the legacy session cookie baker
|
|
|
|
// for compatibility with lila-ws
|
|
|
|
def cookieBaker = new LegacySessionCookieBaker(httpConfiguration.session, cookieSigner)
|
|
|
|
|
|
|
|
override lazy val requestFactory: RequestFactory = {
|
|
|
|
val cookieSigner = new CookieSignerProvider(httpConfiguration.secret).get
|
|
|
|
new DefaultRequestFactory(
|
|
|
|
new DefaultCookieHeaderEncoding(httpConfiguration.cookies),
|
|
|
|
cookieBaker,
|
|
|
|
new LegacyFlashCookieBaker(httpConfiguration.flash, httpConfiguration.secret, cookieSigner)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-06 09:39:42 -07:00
|
|
|
lazy val httpFilters = Seq(wire[lila.app.http.HttpFilter])
|
2019-12-06 10:17:46 -07:00
|
|
|
|
2020-07-31 02:51:01 -06:00
|
|
|
override lazy val httpErrorHandler =
|
|
|
|
new lila.app.http.ErrorHandler(
|
|
|
|
environment = ctx.environment,
|
|
|
|
config = configuration,
|
|
|
|
router = router,
|
|
|
|
mainC = main,
|
|
|
|
lobbyC = lobby
|
|
|
|
)
|
2019-12-05 08:46:00 -07:00
|
|
|
|
|
|
|
implicit def system = actorSystem
|
2020-11-25 14:10:39 -07:00
|
|
|
|
|
|
|
implicit lazy val httpClient: StandaloneWSClient = {
|
2020-08-07 08:22:26 -06:00
|
|
|
import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient
|
2020-08-16 07:06:40 -06:00
|
|
|
import play.api.libs.ws.WSConfigParser
|
2020-08-07 08:22:26 -06:00
|
|
|
import play.api.libs.ws.ahc.{ AhcConfigBuilder, AhcWSClientConfigParser, StandaloneAhcWSClient }
|
|
|
|
new StandaloneAhcWSClient(
|
|
|
|
new DefaultAsyncHttpClient(
|
|
|
|
new AhcConfigBuilder(
|
|
|
|
new AhcWSClientConfigParser(
|
|
|
|
new WSConfigParser(configuration.underlying, environment.classLoader).parse(),
|
|
|
|
configuration.underlying,
|
|
|
|
environment.classLoader
|
|
|
|
).parse()
|
|
|
|
).build()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
2019-12-05 08:46:00 -07:00
|
|
|
|
2019-12-13 22:02:00 -07:00
|
|
|
// dev assets
|
2019-12-13 22:14:46 -07:00
|
|
|
implicit def mimeTypes = fileMimeTypes
|
2019-12-13 22:02:00 -07:00
|
|
|
lazy val devAssetsController = wire[ExternalAssets]
|
|
|
|
|
2019-12-26 18:28:17 -07:00
|
|
|
lazy val shutdown = CoordinatedShutdown(system)
|
|
|
|
|
2019-12-05 08:46:00 -07:00
|
|
|
lazy val boot: lila.app.EnvBoot = wire[lila.app.EnvBoot]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val env: lila.app.Env = boot.env
|
2019-12-05 08:46:00 -07:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val account: Account = wire[Account]
|
|
|
|
lazy val analyse: Analyse = wire[Analyse]
|
|
|
|
lazy val api: Api = wire[Api]
|
2020-07-25 11:50:11 -06:00
|
|
|
lazy val appeal: Appeal = wire[Appeal]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val auth: Auth = wire[Auth]
|
|
|
|
lazy val blog: Blog = wire[Blog]
|
2020-02-24 15:24:33 -07:00
|
|
|
lazy val playApi: PlayApi = wire[PlayApi]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val challenge: Challenge = wire[Challenge]
|
|
|
|
lazy val coach: Coach = wire[Coach]
|
2020-01-16 07:40:33 -07:00
|
|
|
lazy val clas: Clas = wire[Clas]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val coordinate: Coordinate = wire[Coordinate]
|
|
|
|
lazy val dasher: Dasher = wire[Dasher]
|
|
|
|
lazy val dev: Dev = wire[Dev]
|
|
|
|
lazy val editor: Editor = wire[Editor]
|
|
|
|
lazy val event: Event = wire[Event]
|
|
|
|
lazy val export: Export = wire[Export]
|
|
|
|
lazy val fishnet: Fishnet = wire[Fishnet]
|
|
|
|
lazy val forumCateg: ForumCateg = wire[ForumCateg]
|
|
|
|
lazy val forumPost: ForumPost = wire[ForumPost]
|
|
|
|
lazy val forumTopic: ForumTopic = wire[ForumTopic]
|
|
|
|
lazy val game: Game = wire[Game]
|
|
|
|
lazy val i18n: I18n = wire[I18n]
|
|
|
|
lazy val importer: Importer = wire[Importer]
|
|
|
|
lazy val insight: Insight = wire[Insight]
|
|
|
|
lazy val irwin: Irwin = wire[Irwin]
|
|
|
|
lazy val learn: Learn = wire[Learn]
|
|
|
|
lazy val lobby: Lobby = wire[Lobby]
|
|
|
|
lazy val main: Main = wire[Main]
|
2020-01-24 15:48:23 -07:00
|
|
|
lazy val msg: Msg = wire[Msg]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val mod: Mod = wire[Mod]
|
2021-02-19 05:25:36 -07:00
|
|
|
lazy val gameMod: GameMod = wire[GameMod]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val notifyC: Notify = wire[Notify]
|
2021-06-14 16:05:27 -06:00
|
|
|
lazy val oAuth: OAuth = wire[OAuth]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val oAuthApp: OAuthApp = wire[OAuthApp]
|
|
|
|
lazy val oAuthToken: OAuthToken = wire[OAuthToken]
|
|
|
|
lazy val options: Options = wire[Options]
|
|
|
|
lazy val page: Page = wire[Page]
|
|
|
|
lazy val plan: Plan = wire[Plan]
|
|
|
|
lazy val practice: Practice = wire[Practice]
|
|
|
|
lazy val pref: Pref = wire[Pref]
|
|
|
|
lazy val prismic: Prismic = wire[Prismic]
|
|
|
|
lazy val push: Push = wire[Push]
|
|
|
|
lazy val puzzle: Puzzle = wire[Puzzle]
|
|
|
|
lazy val relation: Relation = wire[Relation]
|
2021-04-28 23:36:43 -06:00
|
|
|
lazy val relay: RelayRound = wire[RelayRound]
|
2021-04-23 02:40:52 -06:00
|
|
|
lazy val relayTour: RelayTour = wire[RelayTour]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val report: Report = wire[Report]
|
|
|
|
lazy val round: Round = wire[Round]
|
|
|
|
lazy val search: Search = wire[Search]
|
|
|
|
lazy val setup: Setup = wire[Setup]
|
|
|
|
lazy val simul: Simul = wire[Simul]
|
|
|
|
lazy val stat: Stat = wire[Stat]
|
|
|
|
lazy val streamer: Streamer = wire[Streamer]
|
|
|
|
lazy val study: Study = wire[Study]
|
|
|
|
lazy val team: Team = wire[Team]
|
|
|
|
lazy val timeline: Timeline = wire[Timeline]
|
|
|
|
lazy val tournament: Tournament = wire[Tournament]
|
2019-12-05 08:46:00 -07:00
|
|
|
lazy val tournamentCrud: TournamentCrud = wire[TournamentCrud]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val tv: Tv = wire[Tv]
|
|
|
|
lazy val user: User = wire[User]
|
|
|
|
lazy val userAnalysis: UserAnalysis = wire[UserAnalysis]
|
2019-12-05 08:46:00 -07:00
|
|
|
lazy val userTournament: UserTournament = wire[UserTournament]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val video: Video = wire[Video]
|
2020-04-29 10:31:34 -06:00
|
|
|
lazy val swiss: Swiss = wire[Swiss]
|
2020-09-07 08:10:56 -06:00
|
|
|
lazy val dgt: DgtCtrl = wire[DgtCtrl]
|
2021-01-22 14:43:49 -07:00
|
|
|
lazy val storm: Storm = wire[Storm]
|
2021-03-03 12:11:22 -07:00
|
|
|
lazy val racer: Racer = wire[Racer]
|
2021-02-01 11:27:30 -07:00
|
|
|
lazy val bulkPairing: BulkPairing = wire[BulkPairing]
|
2019-12-05 08:46:00 -07:00
|
|
|
|
2019-12-05 20:01:24 -07:00
|
|
|
// eagerly wire up all controllers
|
2019-12-09 20:14:38 -07:00
|
|
|
val router: Router = {
|
2020-07-08 12:47:36 -06:00
|
|
|
@nowarn val prefix: String = "/"
|
2019-12-09 20:14:38 -07:00
|
|
|
wire[Routes]
|
|
|
|
}
|
2019-12-05 20:01:24 -07:00
|
|
|
|
2019-12-19 21:49:17 -07:00
|
|
|
if (configuration.get[Boolean]("kamon.enabled")) {
|
2019-12-05 20:01:24 -07:00
|
|
|
lila.log("boot").info("Kamon is enabled")
|
|
|
|
kamon.Kamon.loadModules()
|
|
|
|
}
|
2019-12-05 08:46:00 -07:00
|
|
|
}
|