summaryrefslogtreecommitdiff
path: root/examples/crossBuilds/clientserver/server
diff options
context:
space:
mode:
Diffstat (limited to 'examples/crossBuilds/clientserver/server')
l---------examples/crossBuilds/clientserver/server/shared1
-rw-r--r--examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala21
-rw-r--r--examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala46
3 files changed, 68 insertions, 0 deletions
diff --git a/examples/crossBuilds/clientserver/server/shared b/examples/crossBuilds/clientserver/server/shared
new file mode 120000
index 0000000..f32be42
--- /dev/null
+++ b/examples/crossBuilds/clientserver/server/shared
@@ -0,0 +1 @@
+../client/shared \ No newline at end of file
diff --git a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala
new file mode 100644
index 0000000..d657290
--- /dev/null
+++ b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Page.scala
@@ -0,0 +1,21 @@
+package simple
+import scalatags.Text.all._
+
+object Page{
+ val boot =
+ "Client().main(document.getElementById('contents'))"
+ val skeleton =
+ html(
+ head(
+ script(src:="/client-fastopt.js"),
+ link(
+ rel:="stylesheet",
+ href:="https://cdnjs.cloudflare.com/ajax/libs/pure/0.5.0/pure-min.css"
+ )
+ ),
+ body(
+ onload:=boot,
+ div(id:="contents")
+ )
+ )
+}
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