If you are using spray routing, then it should be easy, just provide a route for your static resources. For example you can do the following:
Let's say that your static resources are in /css
, /js
and /img
folders:
def staticPrefixes = List("css", "js", "img") map { pathPrefix(_) } reduce { _ | _ }
with pathPrefix
you are making each path a prefix of an unmatched path. Then you need a directive to extract path to static file from the request, for example you can do it like this:
def stripLeadingSlash(path: String) = if (path startsWith "/") path.tail else path
val staticPath =
staticPrefixes &
cache(routeCache()) &
extract(ctx ⇒ stripLeadingSlash(ctx.request.uri.path.toString))
then construct your route which would manage your resources:
val staticRoutes =
get {
staticPath { path ⇒
getFromResource(path.toString)
}
}