-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a configuration to serve a local directory with a static handler #39968
Comments
Definitely +1 for this. P.S. It should be pretty easy to do this. |
@geoand do you want to add it? |
I am pretty sure anyone could do it 😉. That said, if no one else takes it, I can have a look at some point. |
I commented on the PR - do NOT add multiple static handlers. All the static handlers rely on the same file resolver, which contains a cache. If you have concurrent access (which you can do as soon as your number of event loops is greater than 1), BOOM. We would have to verify that the directories do not overlap and that file names are unique (otherwise, the cache won't work). |
@cescoffier then our docs which tell people to add one are also wrong. |
Yes and no - it can work, but it may not either (in the sense it could leak or corrupt). If your path do not overlap and file names are unique, it is going to work (I still need to check ranges). |
You mean that each handler should serve a unique root, correct?
What does this mean exactly? That different instances of StaticHandler can't serve two totally different files that happen to have the same name? |
Yes, different roots without overlap (including symbolic links and so on). See https://github.com/eclipse-vertx/vert.x/blob/4.5.7/src/main/java/io/vertx/core/file/impl/FileResolverImpl.java#L262 Note the (on purpose) lack of synchronization (and now you understand why I am concerned) |
Yes, I see your point. I am going to close my PR since this needs to be handled properly in Vertx before we do anything in Quarkus to make things easier. |
Note that if we want to support only resources from the file system (not from the classloader), things are way easier (and a custom, optimized static handler can be created in a few minutes) |
Right, the way I see it, this issue is only about file system resources, not classpath resources.
That should be part of Vertx though, no? |
I think we should remove this section from the documentation until this get fixed |
@geoand No, I think it should be in Quarkus as we can improve things at build time. |
Fair enough |
@cescoffier wouldn't that be possible in Vertx to cache with a relative path instead of just the file name? |
@ia3andy check the Vertx Cache implementation, my memory is a bit rusty. |
@ia3andy did you check on the Vert.x side? Pretty sure that |
Maybe we could do this (now that we have GeneratedStaticResourceBuildItem): // for each files in the configured static dir:
String link = PathUtils.toUnixPath(staticDir.relativize(staticFile)); // Make sure we convert \ to / and use the relative path from the directory as link
staticResourcesProducer.produce(new GeneratedStaticResourceBuildItem(link, staticFile)); |
Description
Currently we are suggesting to setup a custom route manually:
https://quarkus.io/guides/http-reference#from-a-local-directory
This would be more elegant and cleaner if it was done in the Quarkus Http using a config
The text was updated successfully, but these errors were encountered: