App skeleton
authorTomas Zeman <tzeman@volny.cz>
Thu, 22 Nov 2018 13:15:29 +0100
changeset 3 48479e4b89d4
parent 2 eb0fb99d0289
child 4 1a1347e8c5be
App skeleton
build.sc
jvm/resources/config.conf
jvm/resources/reference.conf
jvm/src/sqwl/cms/Server.scala
jvm/src/sqwl/cms/Service.scala
jvm/src/sqwl/cms/UrlScheme.scala
jvm/src/sqwl/cms/config.scala
--- a/build.sc	Thu Nov 08 19:12:42 2018 +0100
+++ b/build.sc	Thu Nov 22 13:15:29 2018 +0100
@@ -52,7 +52,6 @@
     "-Xcheckinit",                       // Wrap field accessors to throw an exception on uninitialized access.
     "-Xfuture",                          // Turn on future language features.
     "-target:jvm-1.8",
-    "--illegal-access=warn"
   )}
 }
 
@@ -67,11 +66,13 @@
     ivy"com.typesafe.akka::akka-slf4j:$akkaVer",
     ivy"org.json4s::json4s-native:3.6.2",
     ivy"ch.qos.logback:logback-classic:1.2.3",
-    ivy"com.lihaoyi::scalatags:0.6.7"
+    ivy"com.lihaoyi::scalatags:0.6.7",
+    ivy"org.webjars:bootstrap:4.1.3",
+    ivy"org.webjars:font-awesome:5.5.0"
   )
 
   override def scalacOptions = T{super.scalacOptions.map(_ :+
-    "-Xmacro-settings:conf.output.dir=jvm/src/main/resources"
+    "-Xmacro-settings:conf.output.dir=jvm/resources"
   )}
 
   override def mainClass = Some("sqwl.cms.Server")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/resources/config.conf	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,7 @@
+config {
+  http {
+    interface = localhost
+    port = 8080
+    prefix = cms
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/resources/reference.conf	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,1 @@
+include "config.conf"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/src/sqwl/cms/Server.scala	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,28 @@
+package sqwl.cms
+
+import akka.actor.ActorSystem
+import akka.http.scaladsl.Http
+import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
+import akka.http.scaladsl.server.Directives._
+import akka.stream.{ActorMaterializer, Materializer}
+
+import scala.concurrent.ExecutionContextExecutor
+
+object Server extends App with Service with config with UrlScheme {
+  override implicit val system: ActorSystem = ActorSystem()
+  override implicit val executor: ExecutionContextExecutor = system.dispatcher
+  override implicit val materializer: Materializer = ActorMaterializer()
+
+  private val routes = get {
+    path(http.prefix) {
+      complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "main"))
+    } ~ pathPrefix(http.prefix / ASSETS) {
+      getFromResourceDirectory("META-INF/resources/webjars")
+    } ~ pathPrefix(http.prefix / PUBLIC) {
+      getFromResourceDirectory("public")
+    }
+  }
+
+  Http().bindAndHandle(routes, http.interface, http.port)
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/src/sqwl/cms/Service.scala	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,12 @@
+package sqwl.cms
+
+import akka.actor.ActorSystem
+import akka.stream.Materializer
+
+import scala.concurrent.ExecutionContextExecutor
+
+trait Service {
+  implicit val system: ActorSystem
+  implicit def executor: ExecutionContextExecutor
+  implicit val materializer: Materializer
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/src/sqwl/cms/UrlScheme.scala	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,7 @@
+package sqwl.cms
+
+trait UrlScheme {
+  val ASSETS = "assets"
+  val PUBLIC = "public"
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jvm/src/sqwl/cms/config.scala	Thu Nov 22 13:15:29 2018 +0100
@@ -0,0 +1,13 @@
+package sqwl.cms
+
+import com.wacai.config.annotation.conf
+
+@conf trait config {
+
+  final val http = new {
+    val interface = "localhost"
+    val port = 8080
+    val prefix = "cms"
+  }
+
+}