Skip to content

Instantly share code, notes, and snippets.

@vikasontech
Last active January 19, 2020 07:36
Show Gist options
  • Save vikasontech/bbb78c7509bda0d3597eb3a8b135a954 to your computer and use it in GitHub Desktop.
Save vikasontech/bbb78c7509bda0d3597eb3a8b135a954 to your computer and use it in GitHub Desktop.
package org
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.directives.PathDirectives.pathPrefix
import akka.stream.ActorMaterializer
import org.user.actor.UserDataActor
import org.user.repositories.UserActivityRepositoryImpl
import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn
object WebServer extends App {
implicit val system: ActorSystem = ActorSystem("web-app")
private implicit val dispatcher: ExecutionContextExecutor = system.dispatcher
private implicit val materialize: ActorMaterializer = ActorMaterializer()
implicit val userActivityRepo = new UserActivityRepositoryImpl()
implicit val userDataActorRef: ActorRef = system.actorOf(Props(new UserDataActor()))
private val routeConfig = new RouteConfig()
val routes = {
pathPrefix("api") {
concat(
routeConfig.getRoute,
routeConfig.postRoute,
routeConfig.deleteRoute,
routeConfig.putRoute
)
}
}
val serverFuture = Http().bindAndHandle(routes, "localhost", 8080)
println("Server started ...")
StdIn.readLine()
serverFuture
.flatMap(_.unbind())
.onComplete(_ => system.terminate())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment