-
Notifications
You must be signed in to change notification settings - Fork 412
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 resourcePrefix for Middleware.serveResources #2887
Add a resourcePrefix for Middleware.serveResources #2887
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2887 +/- ##
==========================================
- Coverage 64.39% 64.34% -0.05%
==========================================
Files 156 156
Lines 9148 9150 +2
Branches 1579 1593 +14
==========================================
- Hits 5891 5888 -3
- Misses 3257 3262 +5 ☔ View full report in Codecov by Sentry. |
9976516
to
3ac2749
Compare
As it is, `Middleware.serveResources(path)` going to serve any file at all under src/main/resources, including e.g. somebody's reference.conf file. I added a resourcePrefix parameter for this, so that the resources served can be limited to, e.g., src/main/resources/public. I also added delegates for serveResources and serveDirectory in Routes, as per this suggestion: zio#2450 (comment)
fe7b050
to
8342304
Compare
@sullivan- That addition is needed absolutely 👍 👍 👍 - but to be honest in that case I'd go for the exact same way you posted in discord regarding spring framework and publish under a hard-coded folder under As of now with the default to Also I doubt a bit that we need to have the internal published directory name configurable from the beginning, probably everyone configures it the same and it sounds to me like a implementation detail that we should hide. |
I'm happy to change it if people want. Maybe it's better to just not supply |
@sullivan- I think the principles for serving static assets should be:
Re. 1. I would even go so far as to prevent the user from making this available with zio-http library components. For example, by requiring that the resource path prefix must not be Re. 2. It should be possible to serve from multiple resource path prefixes. For example, you may use a WebJar plus something similar that uses another convention. Re. 3. I really wonder why spring-boot serves from all of these 4 resource paths ( |
BTW, once this it settled, it would be awesome if zio-http would be listed on https://www.webjars.org/documentation! |
Multiple paying clients who each have their own ideas about where the assets belong? |
I agree with @erikvanoosten about |
How about we take what is now merged and:
If this sounds agreeable I can make a PR. One question. We have: def serveDirectory(path: zio.http.Path, docRoot: java.io.File) and: def serveResources(path: zio.http.Path, resourcePrefix: String = ".") Would it be better if the second method took |
I am not sure about how it works exactly, but perhaps this needs to be "/public/"? Or any other way to make sure that it can't serve resources like
As far as I know a |
Followup PR: #2928 |
1. Change the default path from "." to "public". 2. Add a restriction that the path does not have "." as a prefix. as discussed in a prior PR, here: zio#2887 (comment)
* some cleanup on recent work serving files and resources 1. Change the default path from "." to "public". 2. Add a restriction that the path does not have "." as a prefix. as discussed in a prior PR, here: #2887 (comment) * incorporate @erikvanoosten's suggestions - replace `Handler.forbidden` with `require` - firming up logic for resource prefix limitations - some Scaladoc improvements I also fixed a `resourcePrefix` default value from `"."` to `"public"` that I somehow missed before.
As it is,
Middleware.serveResources(path)
going to serve any file at all under src/main/resources, including e.g. somebody's reference.conf file. I added a resourcePrefix parameter for this, so that the resources served can be limited to, e.g., src/main/resources/public.I also added delegates for serveResources and serveDirectory in Routes, as per this suggestion:
#2450 (comment)