-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Filter files more flexibly #139
Comments
This fix went in around/before the time that Vite issue popped up: https://github.com/lukeed/sirv/blob/master/packages/sirv/index.js#L43 In dev mode (what Vite uses last I checked), the URL given to |
Thank you for the quick response! The behavior of Vite is:
The relevant code is https://github.com/vitejs/vite/blob/5c6cf5a2a6577fb8e8ecc66a0411143af3fed042/packages/vite/src/node/server/middlewares/static.ts#L62-L117. |
I'm really not interested in changing anything about sirv, especially related to decoding & encoding URLs. We spent a lot of time in recent years ensuring that the hand-off works correctly. Vite is a devserver, ultimately, so a little bit of extra decoding work isn't going to be problematic for anyone, especially considering that a single URL encode/decode takes less than 0.5ms. Combined, all the other filtering overhead that I see in this file is probably computationally (and wall-time) more expensive. If vite really wants to avoid extra decodes, they can use sirv's same URL parser ( // vite side
let info = parse(req);
// changes
req.url = req._parsedUrl.raw = redirected; This requires that vite have full confidence that they updated all Again, no changes will be made here. What's here works for sirv, its dependents, and is the result of close communications with vite maintainers directly to ensure the above is all true. |
That's a good point. Thank you for your response. |
Currently Vite filters request before passing to sirv, depending on whether the file that is going to be served is allowed to be served.
But this caused an issue. (vitejs/vite#8498)
This was because that Vite needs to imitate how sirv maps URL to file but Vite didn't it properly.
Now I understand what was different between Vite and sirv so I'm able to fix this.
But to fix this, it needs to 1. decode URL 2. filter it 3. encode URL. This is not performant.
So I wonder if I could pass an option to filter files.
This way Vite won't need to imitate sirv and Vite won't need to re-encode the URL.
For example:
This option could be thought as a more flexible version of
opt.dotfiles
,dir
.If this is out of scope, would you consider:
decodeURIComponent
req.decodedUrl
)The text was updated successfully, but these errors were encountered: