Giter Site home page Giter Site logo

Filter files more flexibly about sirv HOT 4 CLOSED

sapphi-red avatar sapphi-red commented on August 21, 2024
Filter files more flexibly

from sirv.

Comments (4)

lukeed avatar lukeed commented on August 21, 2024

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.

sapphi-red avatar sapphi-red commented on August 21, 2024

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:

  1. Vite decodes URL
  2. Vite changes URL (to resolve alias)
  3. Vite filters request passed to sirv by ensureServingAccess
  4. 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.

lukeed avatar lukeed commented on August 21, 2024

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.

sapphi-red avatar sapphi-red commented on August 21, 2024

That's a good point. Thank you for your response.

from sirv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.