Loaded html requests static content from parent directory

137 views
Skip to first unread message

Jack Daniels

unread,
Jan 20, 2015, 8:15:44 AM1/20/15
to spray...@googlegroups.com
Hi guys!

How can I solve issue of missing static content when serving html from Spray (or Akka-Http) ? Base url of my service is /api (even though it should be irrelevant in this case).

Here is my route

get {
  pathPrefix("swagger") {
    pathEndOrSingleSlash {
      getFromResource("swagger-ui/index.html")
    } ~
      getFromResourceDirectory("swagger-ui")
  }
}

Loaded html can find css and js file when I open it as

/api/swagger/

but when I open

/api/swagger (without trailing slash)

loaded html attempts to get content from

/api/css/reset.css instead of /api/swagger/css/reset.css

How should I rewrite my route to cover both cases ?


Thanks!

André

unread,
Jan 20, 2015, 8:26:21 AM1/20/15
to spray...@googlegroups.com
Hi Jack,

I guess you're using relative paths to link to css/*. The trailing slash is important in that case. Thereefore I'd recommend that you redirect swagger to swagger/.

In akka-http we've introduced a special directive for this task.

Cheers
André
Reply all
Reply to author
Forward
0 new messages