-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Set Vite's publicDir and correctly serve public assets earlier in pipeline #5686
Conversation
🦋 Changeset detectedLatest commit: 9cee0ab The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Can we add a test to this to guard against a recurrence of #5672? |
Yes, thanks for the reminder. I had intended to do that. Done! |
packages/kit/src/vite/dev/index.js
Outdated
@@ -180,13 +180,44 @@ export async function dev(vite, vite_config, svelte_config) { | |||
extensions: [] | |||
}); | |||
|
|||
vite.middlewares.use(async (req, res, next) => { | |||
try { | |||
if (!req.url || !req.method) throw new Error('Incomplete request'); |
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.
is this actually a thing that can happen? if i remove this line and get rid of the try-catch
, TypeScript doesn't complain
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.
No, I don't think we need to worry about it. I had copied it from the main middleware. I've removed it in both places. The try
/catch
on the otherhand can't be removed
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.
Are you sure? I don't see any code there that's in danger of throwing
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.
If you try to remove it there's a test that fails with the error below showing where it can throw. It must bring down the whole server because all subsequent tests then fail.
[WebServer] file:///home/bmccann/src/kit/packages/kit/src/vite/dev/index.js:188
const decoded = decodeURI(new URL(base + req.url).pathname);
^
URIError: URI malformed
at decodeURI (<anonymous>)
at packages/kit/src/vite/dev/index.js:188:20
at call (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-561c5231.js:45966:7)
at next (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-561c5231.js:45910:5)
at Function.handle (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-561c5231.js:45913:3)
at Server.app (node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-561c5231.js:45778:37)
at Server.emit (node:events:527:28)
at parserOnIncoming (node:_http_server:956:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
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.
ah, gotcha. fair enough
This is a second stab at #5648 which was reverted for causing #5672
The issue was that we were serving static files from within the Kit middleware, so the transform middleware was being executed on them. This moves static serving into its own middleware so that they're served without the transform middleware being called on them