-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Prefer (allowed) static assets to routes #5070
Conversation
🦋 Changeset detectedLatest commit: 1bce523 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I think the correct fix is probably vitejs/vite#7363 |
@benmccann & @Rich-Harris , I think Vite doesn't take this seriously, but it's a real problem for sveltekit users. If you log |
In lieu of a fix in Vite itself, I think this is a reasonable solution — we mimic Vite's internal logic to determine if an extant file is allowed, and if so we defer to |
expect(r1.status()).toBe(200); | ||
expect(await r1.text()).toContain('http://www.w3.org/2000/svg'); | ||
|
||
const r2 = await request.get('/package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems surprising to me. I wouldn't expect you to be able to get the package.json
, node_modules
, etc. It will also make it available to everyone on your network. I'm not sure that's a huge risk, but I'm not really sure why we'd expose it either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not getting package.json. The test is there to check that it will serve a route called /package.json
despite there being a package.json in the project directory outside the allow
list. Check two lines further down.
node_modules on the other hand are on the allow list so that you can use node_modules!
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
#5066 happens because of #4974, which we need because otherwise files in the project root will shadow stuff in
src/routes
. As of that PR, we attempt to render requests withserver.respond(...)
, and only defer toviteServeStaticMiddleware
if that results in a 404.In the case where you have rest routes, that's no good, because you can get a 200 response even when you're requesting a static asset.
I'm having a hard time figuring out what the correct fix for this is, so I'm just going to leave this failing test here for now.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0