-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Stop serving static files from root directory #7363
Comments
This looks similar to #2587 |
The following features depend on the root-static-serving behavior.
So it cannot be simply removed. |
In these examples, all the files live under Alternatively, though likely more controversial and so probably not preferable to the prior option, I wonder if absolute imports get much usage and must continue to be supported? I didn't know about them until now and have never used them, but have only used relative imports or imports starting with an alias. |
Defaulting
IMO the support for users could be removed. But it is used internally. That's the reason I said it cannot be simply removed. One way to get around this is to add |
I think we should explore this, and I have feedback from Astro that they also consider this request important. But we have already been in v3 alpha long enough now and we need to release the major before Astro 1.0 and Nuxt 3.0. |
Any news 😰 here ? 🙏 |
This fixes the issue described here: #547 (comment) It does so by configuring `direnv` to write its cache for this project in `~/.cache/direnv/layouts`. This is a bit intrusive, but without this workaround, `vite` commands search the local `.direnv` cache for dependencies, and it adds about 10 seconds or more to every `vite` command. Note that the fix comes from here: https://github.com/direnv/direnv/wiki/Customizing-cache-location Before falling back to this workaround, I also tried the following Vite configuration tricks, but none of them worked: https://vitejs.dev/config/server-options.html#server-watch https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude There are multiple (somewhat) related issues currently filed on Vite which suggest that convincing Vite not to look everywhere in the project root directory is a known issue: https://github.com/vitejs/vite/pull/8778/files vitejs/vite#7363 vitejs/vite#8341
We discussed this in the last meeting, and decided it's better to have this enforced by metaframeworks instead. This is because this breaks how Vite works fundamentally (a simple static file server), as some examples sapphi pointed out. Fixing this would require a big refactor and breaking change so it's better to stick with what it has for now. If extra strictness is needed, frameworks can inject middlewares to intercept requests to prevent serving some crucial routes. Closing this as not planned. |
Clear and concise description of the problem
Vite serves files under the root directory:
vite/packages/vite/src/node/server/index.ts
Line 558 in 1e9615d
This has caused some collisions. E.g. a SvelteKit user recently reported that they cannot have a URL path of
tests
because the static serving will attempt to serve thetests
directory (sveltejs/kit#4353).It's also caused quite a bit of confusion with the
publicDir
andbase
options because files end up being available via multiple URLs. E.g. if you havepublic/image.png
you could access it from bothimage.png
and/public/image.png
which has caused a number of users to be confused in the pastHaving the source in the root directory has caused us issues because the root directory is then watched by Chokidar. The output is placed in a sub-directory within the root directory and having the output file being watched caused problems that were extremely difficult to track down and diagnose. It would be nice if the source lived within a subdirectory (SvelteKit projects use the
src
directory)Finally, this has caused a number of people to have security concerns. A lot of people have sensitive files like
.env
in their root project directory. I think we may be special casing.env
now, but a number of people have also been surprised to find that their files are being served. We've attempted to mitigated this withserver.fs.allow
, but have not yet found that to be a suitable solution. It is currently broken for many SvelteKit projects - though it may be fixed after 2.9 is released (#6518). It's also been quite complicated to configure correctly.Suggested solution
Stop serving the root directory. Check that we still correctly serve source maps
Alternative
We could utilize the
server.fs.allow
config to make certain files unservable. Right now if you takepackage.json
off the allow list you will get a 403 and it's impossible to create a middleware that will serve a URL like http://localhost:5173/package.json. But we could remove the 403 message and just continue on or we could serve allowed files, run the other middlewares, and then add a new 403 middleware afterpostHooks
. I would recommend also changing theserver.fs.allow
default from the package root to something a bit safer like['src', publicDir]
and only watching those directories vs the whole project rootAdditional context
@patak-dev and @aleclarson both indicated that they found the current behavior strange as well
Validations
The text was updated successfully, but these errors were encountered: