getFromBrowseableDirectories

Hello there,

I am trying to host a local filepath resource into http using getFromBrowseableDirectories directive.

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._

object Test1 {
  def main(args: Array[String]): Unit = {
    implicit val act = ActorSystem("act1")

    val route = {
      path("entries") { getFromBrowseableDirectories("/tmp/dir1") }
    }

    Http().bindAndHandle(route, "0.0.0.0", 8000)
  }
}

It seems to show up the directory listing (/tmp/dir1 using http://localhost:8000/entries) containing directories and files correctly. But, any attempt to GET on a file or on a directory inside /tmp/dir1 fails with a HTTP/1.1 404 Not Found.
I intend to provide recursive GET support for /tmp/dir1.
On a side note, I am able to surface individual files using getFromFile directive. Perhaps I have to build a recursive path directive with getFromFile & getFromBrowseableDirectories?

Please advice,
Muthu

I think it is because path("entries") matches that path “entries” exactly and nothing more, what you want is likely pathPrefix("entries").

Looks like that is a bit unclear in the docs, I’ve created akka-http/#2995 to improve upon that.

1 Like