Commits

Brent Tubbs committed 842b271

init

  • Participants
  • Tags v1

Comments (0)

Files changed (6)

+syntax: glob
+target
+project/boot
+project/target
+project/plugins/target
+web: target/start Web
+import com.typesafe.startscript.StartScriptPlugin
+
+seq(StartScriptPlugin.startScriptForClassesSettings: _*)
+
+name := "hello"
+
+version := "1.0"
+
+scalaVersion := "2.9.2"
+
+resolvers += "twitter-repo" at "http://maven.twttr.com"
+
+libraryDependencies ++= Seq("com.twitter" % "finagle-core" % "1.9.0", "com.twitter" % "finagle-http" % "1.9.0")

project/build.properties

+sbt.version=0.12.0

project/build.sbt

+resolvers += Classpaths.typesafeResolver
+
+addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.3")

src/main/scala/Web.scala

+import org.jboss.netty.handler.codec.http.{HttpRequest, HttpResponse}
+import com.twitter.finagle.builder.ServerBuilder
+import com.twitter.finagle.http.{Http, Response}
+import com.twitter.finagle.Service
+import com.twitter.util.Future
+import java.net.InetSocketAddress
+import util.Properties
+
+object Web {
+  def main(args: Array[String]) {
+    val port = Properties.envOrElse("PORT", "8080").toInt
+    println("Starting on port:"+port)
+    ServerBuilder()
+      .codec(Http())
+      .name("hello-server")
+      .bindTo(new InetSocketAddress(port))
+      .build(new Hello)
+    println("Started.")
+  }
+}
+
+class Hello extends Service[HttpRequest, HttpResponse] {
+  def apply(req: HttpRequest): Future[HttpResponse] = {
+    val response = Response()
+    response.setStatusCode(200)
+    response.setContentString("Hello World")
+    Future(response)
+  }
+}