Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ version := "0.1"

scalaVersion := "2.12.7"

resolvers ++= Seq("Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Bintray" at "https://jcenter.bintray.com/", //for org.ethereum % leveldbjni-all
"SonaType" at "https://oss.sonatype.org/content/groups/public",
"Typesafe maven releases" at "https://dl.bintray.com/typesafe/maven-releases/",
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/")

libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.3.0"

val circeVersion = "0.12.3"
Expand All @@ -16,8 +22,14 @@ libraryDependencies ++= Seq(

libraryDependencies += "org.ergoplatform" %% "ergo" % "v4.0.13-5251a78b-SNAPSHOT"

resolvers ++= Seq("Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Bintray" at "https://jcenter.bintray.com/", //for org.ethereum % leveldbjni-all
"SonaType" at "https://oss.sonatype.org/content/groups/public",
"Typesafe maven releases" at "https://dl.bintray.com/typesafe/maven-releases/",
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/")
// swaydb just for an experiment
libraryDependencies += "io.swaydb" %% "swaydb" % "0.16.2"

// akka http for API
val AkkaVersion = "2.6.10"
val AkkaHttpVersion = "10.2.4"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion
)
40 changes: 40 additions & 0 deletions src/main/scala/org/ergoplatform/scanner/HttpServer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.ergoplatform.scanner

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import scala.io.StdIn

object HttpServerRoutingMinimal {

def main(args: Array[String]): Unit = {

implicit val system = ActorSystem(Behaviors.empty, "my-system")
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.executionContext

val campaignsRoute = path("campaigns") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, DatabaseStructures.campaigns.count.toString))
}
}

val pledgesRoute = path("pledges") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, DatabaseStructures.pledges.count.toString))
}
}

val route = campaignsRoute ~ pledgesRoute

val bindingFuture = Http().newServerAt("localhost", 7777).bind(route)

println(s"Server online at http://localhost:7777/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
Loading