improvements for `serveStatic`
Describe the feature
I'm using h3 for serving both frontend ui bundle files and an API proxy.
I hit a problem with version 1.7.1 by using staticServe when the user is on a nested route (not root / but for example /books/123).
H3 told me that the route /books/123 doesn't match at all because serveStatic tried to lookup a file name 123 in books folder from the folder we served statically.
I resolved this issue by forcing the url to / when it's not a resource.
I tried the RC version (1.8.0-rc.2, thank @pi0) and I was unfortunately not able to reuse my fix for two reasons:
- for using
staticServe, I'm passing throughfromNodeMiddlewarewhere I have access to the request url to check resource type, where with the newstaticServefrom h3 is used directly. - methods
getContentsandgetMetaare not as easy to handle
My request here is following: Is it possible to get a simpler way for handling nested route without the headaches ?
I probably understand where getContents and getMeta are more complex to use because of supporting different platform, but what about getting a built-in adapter for node ?
Additional information
- [X] Would you be willing to help implement this feature?
Hi dear @edimitchel thanks for the feedback. Indeed it could be easier with implementation. I am thinking to directly support unstorage as a wrapper utility because it makes sure utils will be runtime agnostic.
Can you please somehow make a reproduction for your current usage? Is it mainly that you need to tell utility to add (or strip) a base url?
Yes for sure I have a stackblitz reproduction already but I need to make it work.
Thank you for your interest! I would be happy to make an effort to make it for 1.8.0.
Here the reproduction repo: https://github.com/edimitchel/h3-repro-serve-static-improvement
I will try to put it on stackblitz
Hi @edimitchel are you still planning to work on improvements?
Not for the moment unfortunately