twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 406 forks source link

Finatra does not see files created during runtime #518

Closed MeerKatDev closed 4 years ago

MeerKatDev commented 4 years ago

Expected behavior

As per title - I would like to create a file during execution and serve it as an HTTP response

Actual behavior

It seems like it doesn't see that file, and serves only files that were present at compile time.

Steps to reproduce the behavior

If I copy some text file into the classpath during runtime, Finatra will not see it. The file needs to be there already at compile time.

cacoco commented 4 years ago

@MeerKatDev have you checked the documentation on working with files? See here: https://twitter.github.io/finatra/user-guide/files/index.html. By default we read files from the classpath and it is not cleae what "copy some text file into the classpath during runtime" means, so it would be great if you could provide steps to reproduce.

FWIW, we have many tests that create files at the beginning of the test that are then deleted in the tear down, so it would be great if you could detail exactly what you're doing so we could better understand what is not working.

MeerKatDev commented 4 years ago

I know that page quite well, as it's everything there is on the internet on the topic. That phrase means exactly what it says.

  1. From sbt, I run the program "during runtime",
  2. than I take some text file "test.txt" "copy some text file"
  3. "into the classpath" "target/scala-2.12/classes"
  4. than I try to serve this file through the response.ok.file() function (I can't be more precise than this.)

Finatra will not see this file and give "path not found"

MeerKatDev commented 4 years ago

Also, the static-files link of that page is broken.

cacoco commented 4 years ago

@MeerKatDev thanks for providing more information. The classpath is read by the Java process when it is started, for what you are trying to do, you should instead refer to this location via the -local.doc.root flag (as shown in the tests).

Thanks for pointing out the broken link -- the v1 documentation that it is pointing to was removed some time ago but it does not look like this section was edited.

MeerKatDev commented 4 years ago

you are actively discouraging the use of local.doc.root, does that mean that it is discouraged to serve files created during runtime?

hamdiallam commented 4 years ago

@MeerKatDev

Depends on your use case. If serving files created at runtime is required, the only option is -local.doc.root. Discouraged because depending on how the routes are setup, you could be exposing your filesystem to the internet.

cacoco commented 4 years ago

I think the question has been answered. Please feel free to re-open if not. Thanks!