forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLilaComponents.scala
175 lines (157 loc) · 7.58 KB
/
LilaComponents.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package lila.app
import akka.actor.ActorSystem
import com.softwaremill.macwire.*
import play.api.{ Environment, Configuration, BuiltInComponents }
import play.api.http.HttpRequestHandler
import play.api.libs.crypto.CookieSignerProvider
import play.api.libs.ws.StandaloneWSClient
import play.api.mvc.*
import play.api.mvc.request.*
import play.api.routing.Router
import play.api.http.FileMimeTypes
import play.api.inject.ApplicationLifecycle
final class LilaComponents(
val environment: Environment,
val applicationLifecycle: ApplicationLifecycle,
val configuration: Configuration
) extends BuiltInComponents:
lazy val controllerComponents: ControllerComponents = DefaultControllerComponents(
defaultActionBuilder,
playBodyParsers,
fileMimeTypes,
executionContext
)
// https://www.scala-lang.org/api/2.13.4/Executor%24.html#global:Executor
given executor: Executor = lila.Lila.defaultExecutor
lila.log("boot").info {
val java = System.getProperty("java.version")
val mem = Runtime.getRuntime.maxMemory() / 1024 / 1024
val appVersionCommit = ~configuration.getOptional[String]("app.version.commit")
val appVersionDate = ~configuration.getOptional[String]("app.version.date")
s"lila ${environment.mode} $appVersionCommit $appVersionDate / scala 3 / java $java, memory: ${mem}MB"
}
import _root_.controllers.*
// we want to use the legacy session cookie baker
// for compatibility with lila-ws
def cookieBaker = LegacySessionCookieBaker(httpConfiguration.session, cookieSigner)
override lazy val requestFactory: RequestFactory =
val cookieSigner = CookieSignerProvider(httpConfiguration.secret).get
DefaultRequestFactory(
DefaultCookieHeaderEncoding(httpConfiguration.cookies),
cookieBaker,
LegacyFlashCookieBaker(httpConfiguration.flash, httpConfiguration.secret, cookieSigner)
)
lazy val httpFilters = Seq(wire[lila.app.http.HttpFilter])
override lazy val httpErrorHandler =
lila.app.http.ErrorHandler(
environment = environment,
config = configuration,
router = router,
mainC = main,
lobbyC = lobby
)
override lazy val httpRequestHandler: HttpRequestHandler =
lila.app.http.LilaHttpRequestHandler(
router,
httpErrorHandler,
httpConfiguration,
httpFilters,
controllerComponents
)
given ActorSystem = actorSystem
implicit lazy val httpClient: StandaloneWSClient =
import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient
import play.api.libs.ws.WSConfigParser
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()
).modifyUnderlying(_.setIoThreadsCount(8)).build()
)
)
// dev assets
given FileMimeTypes = fileMimeTypes
lazy val devAssetsController = wire[ExternalAssets]
lazy val boot: lila.app.EnvBoot = wire[lila.app.EnvBoot]
lazy val env: lila.app.Env = boot.env
lazy val account: Account = wire[Account]
lazy val analyse: Analyse = wire[Analyse]
lazy val api: Api = wire[Api]
lazy val appealC: appeal.Appeal = wire[appeal.Appeal]
lazy val auth: Auth = wire[Auth]
lazy val blog: Blog = wire[Blog]
lazy val playApi: PlayApi = wire[PlayApi]
lazy val challenge: Challenge = wire[Challenge]
lazy val coach: Coach = wire[Coach]
lazy val clasC: clas.Clas = wire[clas.Clas]
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]
lazy val msg: Msg = wire[Msg]
lazy val mod: Mod = wire[Mod]
lazy val gameMod: GameMod = wire[GameMod]
lazy val notifyC: Notify = wire[Notify]
lazy val oAuth: OAuth = wire[OAuth]
lazy val oAuthToken: OAuthToken = wire[OAuthToken]
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]
lazy val relay: RelayRound = wire[RelayRound]
lazy val relayTour: RelayTour = wire[RelayTour]
lazy val reportC: report.Report = wire[report.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 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]
lazy val tournamentCrud: TournamentCrud = wire[TournamentCrud]
lazy val tv: Tv = wire[Tv]
lazy val user: User = wire[User]
lazy val userAnalysis: UserAnalysis = wire[UserAnalysis]
lazy val userTournament: UserTournament = wire[UserTournament]
lazy val video: Video = wire[Video]
lazy val swiss: Swiss = wire[Swiss]
lazy val dgt: DgtCtrl = wire[DgtCtrl]
lazy val storm: Storm = wire[Storm]
lazy val racer: Racer = wire[Racer]
lazy val ublog: Ublog = wire[Ublog]
lazy val tutor: Tutor = wire[Tutor]
lazy val bulkPairing: BulkPairing = wire[BulkPairing]
lazy val opening: Opening = wire[Opening]
// eagerly wire up all controllers
private val appealRouter: _root_.router.appeal.Routes = wire[_root_.router.appeal.Routes]
private val reportRouter: _root_.router.report.Routes = wire[_root_.router.report.Routes]
private val clasRouter: _root_.router.clas.Routes = wire[_root_.router.clas.Routes]
val router: Router = wire[_root_.router.router.Routes]
if (configuration.get[Boolean]("kamon.enabled"))
lila.log("boot").info("Kamon is enabled")
kamon.Kamon.init()