h3 icon indicating copy to clipboard operation
h3 copied to clipboard

improvements for `serveStatic`

Open edimitchel opened this issue 2 years ago • 5 comments

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:

  1. for using staticServe, I'm passing through fromNodeMiddleware where I have access to the request url to check resource type, where with the new staticServe from h3 is used directly.
  2. methods getContents and getMeta are 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?

edimitchel avatar Aug 04 '23 14:08 edimitchel

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?

pi0 avatar Aug 07 '23 10:08 pi0

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.

edimitchel avatar Aug 07 '23 10:08 edimitchel

Here the reproduction repo: https://github.com/edimitchel/h3-repro-serve-static-improvement

I will try to put it on stackblitz

edimitchel avatar Aug 09 '23 19:08 edimitchel

Hi @edimitchel are you still planning to work on improvements?

pi0 avatar Oct 03 '23 18:10 pi0

Not for the moment unfortunately

edimitchel avatar Oct 03 '23 18:10 edimitchel