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 | 43 |
1 files changed, 43 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..6b2fea3 --- /dev/null +++ b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala @@ -0,0 +1,43 @@ +package simple + +import akka.actor.ActorSystem +import spray.http.{HttpEntity, MediaTypes} +import spray.routing.SimpleRoutingApp + +object Server extends SimpleRoutingApp{ + + def main(args: Array[String]): Unit = { + implicit val system = ActorSystem() + startServer("localhost", port = 8080){ + get{ + pathSingleSlash{ + complete{ + HttpEntity( + MediaTypes.`text/html`, + Page.skeleton.render + ) + } + } ~ + getFromResourceDirectory("") + } ~ + post{ + path("ajax"){ + extract(_.request.entity.asString) { e => + complete { + val (dir, last) = e.splitAt(e.lastIndexOf("/") + 1) + val files = + Option(new java.io.File("./" + dir).listFiles()) + .toSeq.flatten + upickle.write( + for{ + f <- files + if f.getName.startsWith(last) + } yield FileData(f.getName, f.length()) + ) + } + } + } + } + } + } +}
\ No newline at end of file |