Skip to content

Instantly share code, notes, and snippets.

@przemek-pokrywka
Last active May 7, 2016 22:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save przemek-pokrywka/39e7459e0b7ae3f7fb35b9320a57c6dc to your computer and use it in GitHub Desktop.
Save przemek-pokrywka/39e7459e0b7ae3f7fb35b9320a57c6dc to your computer and use it in GitHub Desktop.
Serve a webpage using Play framework with a simple script. Nothing more, than Linux and Java required. Thanks to brilliant work of Alexandre Archambault, @li_haoyi and Play developers.
#!/bin/bash
test -e ~/.coursier/cr || (mkdir -p ~/.coursier && wget -q -O ~/.coursier/cr https://git.io/vgvpD && chmod +x ~/.coursier/cr)
CLASSPATH="$(~/.coursier/cr fetch -q -p \
\
com.typesafe.play:play-netty-server_2.11:2.5.0 \
com.typesafe.play:play_2.11:2.5.0 \
com.lihaoyi:ammonite-repl_2.11.7:0.5.2 \
\
)" java \
-Dplay.crypto.secret=foo.bar.baz \
-Dconfig.resource=reference.conf \
ammonite.repl.Main <(cat << "EOF"
import play.core.server._
import play.api.routing.sird._
import play.api.mvc._
val server = NettyServer.fromRouter(ServerConfig(
port = Some(19000),
address = "127.0.0.1"
)) {
case GET(p"/hello/$to") => Action {
Results.Ok(s"Hello $to")
}
}
readLine
server.stop()
EOF
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment