Skip to content

Commit

Permalink
simplify first run, serve assets by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 12, 2019
1 parent 23d81ee commit 7bb8416
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Use [GitHub issues](https://github.com/ornicar/lila/issues) for bug reports and
Installation
------------

`./lila`
`run`

The Wiki describes [how to setup a development environment](https://github.com/ornicar/lila/wiki/Lichess-Development-Onboarding).

The source code is available for learning and contribution, but please don't just setup a public Lichess clone. Don't expect developers to help you run your own instance. Questions about the installation and runtime issues will probably be ignored.
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import views._

final class Main(
env: Env,
prismicC: Prismic
prismicC: Prismic,
assetsC: Assets
) extends LilaController(env) {

private lazy val blindForm = Form(tuple(
Expand Down Expand Up @@ -179,4 +180,6 @@ Disallow: /games/export
}
}.fuccess
}

def devAsset(@silent v: String, file: String) = assetsC.at(file)
}
18 changes: 9 additions & 9 deletions app/http/HttpFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ final class HttpFilter(env: Env)(implicit val mat: Materializer) extends Filter
private val net = env.net
private val logger = lila.log("http")

def apply(nextFilter: RequestHeader => Fu[Result])(req: RequestHeader): Fu[Result] = {

val startTime = nowMillis

redirectWrongDomain(req) map fuccess getOrElse {
nextFilter(req) dmap addApiResponseHeaders(req) dmap { result =>
monitoring(req, startTime, result)
result
def apply(nextFilter: RequestHeader => Fu[Result])(req: RequestHeader): Fu[Result] =
if (HTTPRequest isAssets req) nextFilter(req)
else {
val startTime = nowMillis
redirectWrongDomain(req) map fuccess getOrElse {
nextFilter(req) dmap addApiResponseHeaders(req) dmap { result =>
monitoring(req, startTime, result)
result
}
}
}
}

private def monitoring(req: RequestHeader, startTime: Long, result: Result) = {
val actionName = HTTPRequest actionName req
Expand Down
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sources in doc in Compile := List()
publishArtifact in (Compile, packageDoc) := false
// disable publishing the main sources jar
publishArtifact in (Compile, packageSrc) := false
PlayKeys.playDefaultPort := 9663
// don't stage the conf dir
PlayKeys.externalizeResources := false
// shorter prod classpath
Expand All @@ -34,7 +33,10 @@ libraryDependencies ++= Seq(
) ++ silencer.bundle

resourceDirectory in Assets := (sourceDirectory in Compile).value / "assets"
unmanagedResourceDirectories in Assets ++= (if (scala.sys.env.get("SERVE_ASSETS").exists(_ == "1")) Seq(baseDirectory.value / "public") else Nil)
unmanagedResourceDirectories in Assets ++= {
if (scala.sys.env.get("SERVE_ASSETS").exists(_ == "1")) Seq(baseDirectory.value / "public")
else Nil
}

scalariformPreferences := scalariformPrefs(scalariformPreferences.value)
excludeFilter in scalariformFormat := "*Routes*"
Expand Down
7 changes: 0 additions & 7 deletions conf/application.conf.default
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
include "base"

# copy to conf/application.conf, then
# override values from base.conf here

net {
domain = localhost
socket.domain = localhost
asset.domain = assets.localhost
}
10 changes: 7 additions & 3 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ mongodb {
mongo-async-driver = ${akka}
}
net {
domain = "localhost:9663"
socket.domain = ${net.domain}
domain = "localhost:9000"
socket.domain = "localhost:9664"
asset.domain = ${net.domain}
protocol = "http://"
base_url = ${net.protocol}${net.domain}
ip = "127.0.0.1"
email = "[email protected]"
email = ""
crawlable = false
ratelimit = true
}
Expand Down Expand Up @@ -49,6 +49,10 @@ play {
maxInitialLineLength = 2048 # 4096
}
}
assets {
path = "/public"
urlPrefix = "/assets"
}
}
app {
scheduler {
Expand Down
3 changes: 2 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ POST /jsmon/:event controllers.Main.jsmon(event: String)

GET /swag controllers.Main.movedPermanently(to: String = "https://shop.spreadshirt.com/lichess-org")

GET /assets/*file controllers.Assets.versioned(file)
GET /assets/_$v<\w{6}>/*file controllers.Main.devAsset(v, file)
GET /assets/*file controllers.Assets.at(v, file)

GET /robots.txt controllers.Main.robots

Expand Down
4 changes: 2 additions & 2 deletions lila
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# We use .sbtopts instead
export SBT_OPTS=""

# For development without nginx (not recommended).
export SERVE_ASSETS=0
# For development without nginx
export SERVE_ASSETS=1

if [ ! -f "conf/application.conf" ]; then
cp conf/application.conf.default conf/application.conf
Expand Down
2 changes: 2 additions & 0 deletions modules/common/src/main/HTTPRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ object HTTPRequest {
def isApi(req: RequestHeader) = req.path startsWith "/api/"
def isApiOrApp(req: RequestHeader) = isApi(req) || appOrigin(req).isDefined

def isAssets(req: RequestHeader) = req.path startsWith "/assets/"

def userAgent(req: RequestHeader): Option[String] = req.headers get HeaderNames.USER_AGENT

val isAndroid = UaMatcher("""(?i)android.+mobile""")
Expand Down

0 comments on commit 7bb8416

Please sign in to comment.