com-lihaoyi/cask

Static files serving: folder name can't begin with '/'

Closed this issue · 0 comments

I have the following route for static files (yes, copied from the example!):

  @cask.staticFiles("/static/file", headers = Seq("Cache-Control" -> "max-age=31536000"))
  def staticFileRoutes(): String =
    val r = Constants.outputDirectory
    println(s"JLX: static folder returned: '$r'.")
    r

When I use an output directory name (value of "Constants.outputDirectory" above) starting with one or multiple '/', the Cask framework strips the leading '/', resulting in a file not found error.

It took me a long time to figure out what was the error. I found it using strace, which shows clearly that the file that the web server tries to open does not start with the '/' character.

strace output:

write(1, "TTS_OUTPUT_DIRECTORY = /entrepot"..., 36TTS_OUTPUT_DIRECTORY = /entrepot/tts) = 36
[pid 1184012] futex(0x7fd9b0062e7c, FUTEX_WAIT_BITSET_PRIVATE, 0, {tv_sec=5573577, tv_nsec=522348891}, FUTEX_BITSET_MATCH_ANYJLX: static folder returned: '/entrepot/tts'. <unfinished ...>
[pid 1184025] access("entrepot/tts/toto.ogg", F_OK) = -1 ENOENT (No such file or directory)

Thank you.