blob: 876683e7e35a7c39ce5798e486d1858c147e2866 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package cask.endpoints
import cask.main.Endpoint
import cask.model.Request
class staticFiles(val path: String) extends Endpoint{
type Output = String
val methods = Seq("get")
type Input = Seq[String]
type InputParser[T] = QueryParamReader[T]
override def subpath = true
def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
delegate(Map()).map(t =>
cask.model.StaticFile(t + "/" + ctx.remainingPathSegments.filter(s => s != "." && s != "..").mkString("/"))
)
}
def wrapPathSegment(s: String): Input = Seq(s)
}
class staticResources(val path: String, resourceRoot: ClassLoader = getClass.getClassLoader) extends Endpoint{
type Output = String
val methods = Seq("get")
type Input = Seq[String]
type InputParser[T] = QueryParamReader[T]
override def subpath = true
def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
delegate(Map()).map(t =>
cask.model.StaticResource(t + "/" + ctx.remainingPathSegments.filter(s => s != "." && s != "..").mkString("/"), resourceRoot)
)
}
def wrapPathSegment(s: String): Input = Seq(s)
}
|