blob: a4b85aee82407a6a4e058410f6ed7841e22ad36e (
plain) (
blame)
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
|
package byspel
package app
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.server.{Directives, Route}
import spray.json.DefaultJsonProtocol
import scala.concurrent.Await
import scala.concurrent.duration._
trait HttpApi
extends Directives
with SprayJsonSupport
with DefaultJsonProtocol {
def route: Route
}
trait HttpApp extends App { self: HttpApi =>
override def start() = {
super.start()
log("binding to interface")
val future =
Http().bindAndHandle(route, config.http.address, config.http.port)
Await.result(future, 2.seconds)
}
}
trait DatabaseApi extends Tables {
val profile = Tables.profile
import profile.api._
def database: Database
}
trait DatabaseApp extends App { self: DatabaseApi =>
import profile.api.Database
lazy val database: Database = Database.forURL(
s"jdbc:sqlite:${config.database.file}",
driver = "org.sqlite.JDBC"
)
override def start() = {
super.start()
log("initializing database")
database
}
}
|