Skip to content

Instantly share code, notes, and snippets.

@lihaoyi
Last active April 1, 2016 13:27
Show Gist options
  • Save lihaoyi/dae2cbdeae04e2c5afbcbc4d074bfea4 to your computer and use it in GitHub Desktop.
Save lihaoyi/dae2cbdeae04e2c5afbcbc4d074bfea4 to your computer and use it in GitHub Desktop.
haoyi-mbp:test haoyi$ cat Server.scala
load.ivy("com.typesafe.play" %% "play" % "2.5.0")
load.ivy("com.typesafe.play" %% "play-netty-server" % "2.5.0")
load.ivy("org.scalaj" %% "scalaj-http" % "2.2.1")
@
import play.core.server._, play.api.routing.sird._, play.api.mvc._
// Workaround for #371
Thread.currentThread.setContextClassLoader(getClass.getClassLoader)
val config = play.api.Configuration(
"play.server.netty" -> Map(
"maxInitialLineLength" -> 4096,
"maxHeaderSize" -> 8192,
"maxChunkSize" -> 8192,
"log.wire" -> false,
"eventLoopThreads" -> 0,
"transport" -> "jdk",
"option.child" -> Map()
)
)
val server = NettyServer.fromRouter(new ServerConfig(
rootDir = new java.io.File("."),
port = Some(19000), sslPort = None,
address = "127.0.0.1", mode = play.api.Mode.Dev,
properties = System.getProperties,
configuration = config
)) {
case GET(p"/hello/$to") => Action { Results.Ok(s"Hello $to") }
}
import scalaj.http._
show(Http("http://localhost:19000/hello/bar").asString)
haoyi-mbp:test haoyi$ ~/amm Server.scala
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
HttpResponse(
"Hello bar",
200,
Map(
"Content-Length" -> Vector("9"),
"Content-Type" -> Vector("text/plain; charset=utf-8"),
"Date" -> Vector("Fri, 01 Apr 2016 13:26:40 GMT"),
"Status" -> Vector("HTTP/1.1 200 OK")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment