base/src/sqwl/cms/Server.scala
changeset 33 fa0f19a74283
parent 32 2d14f02ba3bd
equal deleted inserted replaced
32:2d14f02ba3bd 33:fa0f19a74283
    22 import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpHeader, HttpResponse}
    22 import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpHeader, HttpResponse}
    23 import akka.http.scaladsl.server.Directives._
    23 import akka.http.scaladsl.server.Directives._
    24 
    24 
    25 import scala.collection.immutable
    25 import scala.collection.immutable
    26 import scala.concurrent.ExecutionContextExecutor
    26 import scala.concurrent.ExecutionContextExecutor
    27 import scala.io.StdIn
       
    28 
    27 
    29 trait Server extends App with Service[Nothing] with config with UrlScheme {
    28 trait Server extends App with Service[Nothing] with config with UrlScheme {
    30 
    29 
    31   override implicit val system: ActorSystem[Nothing] =
    30   override implicit val system: ActorSystem[Nothing] =
    32     ActorSystem(Behaviors.empty, "Server")
    31     ActorSystem(Behaviors.empty, "Server")
    52       pathEnd {
    51       pathEnd {
    53         complete(asHtml(Dashboard))
    52         complete(asHtml(Dashboard))
    54       } ~ pathPrefix(asArticle) { article =>
    53       } ~ pathPrefix(asArticle) { article =>
    55         pathEnd {
    54         pathEnd {
    56           complete(asHtml(ViewArticle(article)))
    55           complete(asHtml(ViewArticle(article)))
    57         } ~ getFromDirectory(article.assets.toString)
    56         } ~ getFromDirectory(content.articleAssets(article).toString)
    58       } ~ path(asCategory) { category =>
    57       } ~ path(asCategory) { category =>
    59         complete(asHtml(ViewCategory(category)))
    58         complete(asHtml(ViewCategory(category)))
    60       } ~ path(TAG / asTag) { tag =>
    59       } ~ path(TAG / asTag) { tag =>
    61         complete(asHtml(ViewTag(tag)))
    60         complete(asHtml(ViewTag(tag)))
    62       }
    61       }
    70       getFromDirectory(content.publicAssets.toString)
    69       getFromDirectory(content.publicAssets.toString)
    71     }
    70     }
    72   }
    71   }
    73 
    72 
    74   Http().newServerAt(http.interface, http.port).bind(routes)
    73   Http().newServerAt(http.interface, http.port).bind(routes)
    75   if (run.mode == "devel") {
       
    76     system.log.info("Click `Enter` to close application...")
       
    77     StdIn.readLine()
       
    78     system.terminate()
       
    79   }
       
    80 
    74 
    81 }
    75 }