Skip to content

Instantly share code, notes, and snippets.

@lihaoyi
Last active April 18, 2017 08:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save lihaoyi/77f61cbb1e3e6c93e664d6ef86306780 to your computer and use it in GitHub Desktop.
Save lihaoyi/77f61cbb1e3e6c93e664d6ef86306780 to your computer and use it in GitHub Desktop.
play.scala
/**
* Single-file play framework application! Make sure everything
* works, as this is the test case that un-earthed #371
*/
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._
import scalaj.http._
val server = NettyServer.fromRouter(new ServerConfig(
rootDir = new java.io.File("."),
port = Some(19000), sslPort = None,
address = "0.0.0.0", mode = play.api.Mode.Dev,
properties = System.getProperties,
configuration = play.api.Configuration(
"play.server.netty" -> Map(
"maxInitialLineLength" -> 4096,
"maxHeaderSize" -> 8192,
"maxChunkSize" -> 8192,
"log.wire" -> false,
"eventLoopThreads" -> 0,
"transport" -> "jdk",
"option.child" -> Map()
)
)
)) {
case GET(p"/hello/$to") => Action { Results.Ok(s"Hello $to") }
}
Console.readLine()
server.stop()
@scalway
Copy link

scalway commented Apr 18, 2017

version with play:2.6-M4 does not work for me :(

/**
	* Single-file play framework application! Make sure everything
	* works, as this is the test case that un-earthed #371
	*/
import $ivy.`com.typesafe.play::play:2.6.0-M4`
import $ivy.`com.typesafe.play::play-netty-server:2.6.0-M4`
import $ivy.`org.scalaj::scalaj-http:2.3.0`

import play.core.server._, play.api.routing.sird._, play.api.mvc._
import scalaj.http._
val server = NettyServer.fromRouter(new ServerConfig(
	rootDir = new java.io.File("."),
	port = Some(19000), sslPort = None,
	address = "localhost", mode = play.api.Mode.Dev,
	properties = System.getProperties,
	configuration = play.api.Configuration(
		"play.server.netty" -> Map(
			"maxInitialLineLength" -> 4096,
			"maxHeaderSize" -> 8192,
			"maxChunkSize" -> 8192,
			"log.wire" -> false,
			"eventLoopThreads" -> 4,
			"transport" -> "jdk",
			"option.child" -> Map()
		)
	)
)) {
	case GET(p"/hello/$to") => Action { Results.Ok(s"Hello $to") }
}

Console.readLine()
server.stop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment