Comments (4)
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 sirv
won't ever leave the dir
provided ("public" in this case). And in non-dev mode, the internal Cache is only populated with files from dir
recursively, so any attempt made to leave dir
will result in a 404 anyway.
from sirv.
Thank you for the quick response!
Maybe you are confusing vitejs/vite#8498 with vitejs/vite#2820? It has the same name but vitejs/vite#8498 is created last month.
The behavior of Vite is:
- Vite decodes URL
- Vite changes URL (to resolve alias)
- Vite filters request passed to sirv by ensureServingAccess
- sirv is called with the changed
req.url
which is decoded (because it was manipulated to resolve alias)
The relevant code is https://github.com/vitejs/vite/blob/5c6cf5a2a6577fb8e8ecc66a0411143af3fed042/packages/vite/src/node/server/middlewares/static.ts#L62-L117.
from sirv.
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 (@polka/url@next
, which (1) only decodes if it needs to and (2) can setup a req._parsedUrl
dict that can be abused/reused once the request is handed off to sirv.
// vite side
let info = parse(req);
// changes
req.url = req._parsedUrl.raw = redirected;
This requires that vite have full confidence that they updated all _parsedUrl
keys correctly, since it'll be reused as is if req.url === req._parsedUrl.raw
.
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.
from sirv.
That's a good point. Thank you for your response.
from sirv.
Related Issues (20)
- Support for "." in pathnames
- Add Changelog HOT 2
- Document "dev mode"
- [feature] option to fail on port conflict HOT 1
- `/foo%2Fbar.txt` returns `/foo/bar.txt`
- Range request overlap is handled incorrectly HOT 2
- Option to enforce case sensitivity HOT 1
- Add some API to refresh / update the cache HOT 1
- Question: reduce cache size? HOT 2
- net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK) HOT 1
- [Feature Request] New option `base`. (Aka base path, public path, asssets URL root.)
- When static file changed to longer during run HOT 3
- Dev mode with cache control HOT 1
- Support for POST request HOT 2
- Add `charset=utf-8`
- Range suffix requests return prefixes instead
- Add "watch" mode to update filesystem cache HOT 2
- Downloading gzipped files in browsers HOT 4
- Support filenames that end with `+`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sirv.