Skip to content

Commit de1e163

Browse files
committed
Made the implementation easier
1 parent accf7dc commit de1e163

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/main/scala/de/upb/cs/swt/delphi/webapi/Server.scala

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
package de.upb.cs.swt.delphi.webapi
22

3-
import akka.actor.ActorSystem
4-
import akka.http.scaladsl.Http
5-
import akka.http.scaladsl.server.Directives._
6-
import akka.stream.ActorMaterializer
7-
8-
import scala.io.StdIn
3+
import akka.http.scaladsl.server.HttpApp
94

105
/**
116
* Web server configuration for Delphi web API.
127
*/
13-
object Server {
14-
15-
def main(args: Array[String]): Unit = {
16-
implicit val system = ActorSystem()
17-
implicit val materializer = ActorMaterializer()
18-
implicit val executionContext = system.dispatcher
8+
object Server extends HttpApp {
199

20-
val route =
10+
override def routes =
2111
path("version") { version } ~
2212
path("features") { features } ~
2313
pathPrefix("search" / Remaining) { query => search(query) } ~
2414
pathPrefix("retrieve" / Remaining) { identifier => retrieve(identifier) }
2515

2616

27-
val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
28-
29-
println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
30-
StdIn.readLine() // let it run until user presses return
31-
bindingFuture
32-
.flatMap(_.unbind()) // trigger unbinding from the port
33-
.onComplete(_ => system.terminate()) // and shutdown when done
34-
}
35-
3617
private def version = {
3718
get {
3819
complete {
@@ -63,5 +44,11 @@ object Server {
6344
}
6445
}
6546

47+
def main(args: Array[String]): Unit = {
48+
Server.startServer("0.0.0.0", 8080)
49+
}
50+
6651

6752
}
53+
54+

0 commit comments

Comments
 (0)