summaryrefslogtreecommitdiff
path: root/example/staticFiles2/app
diff options
context:
space:
mode:
Diffstat (limited to 'example/staticFiles2/app')
-rw-r--r--example/staticFiles2/app/resources/cask/example.txt1
-rw-r--r--example/staticFiles2/app/src/StaticFiles2.scala19
-rw-r--r--example/staticFiles2/app/test/src/ExampleTests.scala35
3 files changed, 55 insertions, 0 deletions
diff --git a/example/staticFiles2/app/resources/cask/example.txt b/example/staticFiles2/app/resources/cask/example.txt
new file mode 100644
index 0000000..5184576
--- /dev/null
+++ b/example/staticFiles2/app/resources/cask/example.txt
@@ -0,0 +1 @@
+the quick brown fox jumps over the lazy dog \ No newline at end of file
diff --git a/example/staticFiles2/app/src/StaticFiles2.scala b/example/staticFiles2/app/src/StaticFiles2.scala
new file mode 100644
index 0000000..7354cdb
--- /dev/null
+++ b/example/staticFiles2/app/src/StaticFiles2.scala
@@ -0,0 +1,19 @@
+package app
+object StaticFiles2 extends cask.MainRoutes{
+ @cask.get("/")
+ def index() = {
+ "Hello!"
+ }
+
+ @cask.staticFiles("/static/file", headers = Seq("Cache-Control" -> "max-age=31536000"))
+ def staticFileRoutes() = "app/resources/cask"
+
+ @cask.decorators.compress
+ @cask.staticResources("/static/resource")
+ def staticResourceRoutes() = "cask"
+
+ @cask.staticResources("/static/resource2")
+ def staticResourceRoutes2() = "."
+
+ initialize()
+}
diff --git a/example/staticFiles2/app/test/src/ExampleTests.scala b/example/staticFiles2/app/test/src/ExampleTests.scala
new file mode 100644
index 0000000..514f534
--- /dev/null
+++ b/example/staticFiles2/app/test/src/ExampleTests.scala
@@ -0,0 +1,35 @@
+package app
+import io.undertow.Undertow
+
+import utest._
+
+object ExampleTests extends TestSuite{
+ def withServer[T](example: cask.main.Main)(f: String => T): T = {
+ val server = Undertow.builder
+ .addHttpListener(8080, "localhost")
+ .setHandler(example.defaultHandler)
+ .build
+ server.start()
+ val res =
+ try f("http://localhost:8080")
+ finally server.stop()
+ res
+ }
+
+ val tests = Tests{
+
+ test("StaticFiles") - withServer(StaticFiles2){ host =>
+ requests.get(s"$host/static/file/example.txt").text() ==>
+ "the quick brown fox jumps over the lazy dog"
+
+ requests.get(s"$host/static/resource/example.txt").text() ==>
+ "the quick brown fox jumps over the lazy dog"
+
+ requests.get(s"$host/static/resource2/cask/example.txt").text() ==>
+ "the quick brown fox jumps over the lazy dog"
+
+ requests.get(s"$host/static/file/../../../build.sc").statusCode ==> 404
+ }
+
+ }
+}