diff options
Diffstat (limited to 'examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala')
-rw-r--r-- | examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala new file mode 100644 index 0000000..e9038b5 --- /dev/null +++ b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala @@ -0,0 +1,46 @@ +package simple + +import akka.actor.ActorSystem +import spray.http.{HttpEntity, MediaTypes} +import spray.routing.SimpleRoutingApp + +import scala.util.Properties + +object Server extends SimpleRoutingApp{ + def main(args: Array[String]): Unit = { + implicit val system = ActorSystem() + val port = Properties.envOrElse("PORT", "8080").toInt + startServer("0.0.0.0", port = port){ + get{ + pathSingleSlash{ + complete{ + HttpEntity( + MediaTypes.`text/html`, + Page.skeleton.render + ) + } + } ~ + getFromResourceDirectory("") + } ~ + post{ + path("ajax" / "list"){ + extract(_.request.entity.asString) { e => + complete { + upickle.write(list(e)) + } + } + } + } + } + } + def list(path: String) = { + val (dir, last) = path.splitAt(path.lastIndexOf("/") + 1) + val files = + Option(new java.io.File("./" + dir).listFiles()) + .toSeq.flatten + for{ + f <- files + if f.getName.startsWith(last) + } yield FileData(f.getName, f.length()) + } +}
\ No newline at end of file |