Skip to content
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

Use req.originalUrl for better Vite compatibility #7343

Merged
merged 4 commits into from Oct 28, 2022

Conversation

benmccann
Copy link
Member

This gets us pretty darn close to being able to set the base option in Vite correctly. Right now we hardcode it to ./, which isn't correct and I suspect is one of the reasons the highly upvoted #2958 doesn't work. There's one more thing we'll need to fix it which is vitejs/vite#9236 and I'm working on getting that in as part of Vite 4

The reason we need this is that Vite rewrites the url to strip out the base path, which makes the url not what we might expect. I looked into changing that in Vite and discussed with the Vite team. While there's the possibility we might be able to do it, it's not easy and would affect the entire Vite ecosystem, so we'd need to get buy in from all the other frameworks. And actually, what Vite is doing is how the Express ecosystem works and is explicitly what originalUrl was provided for, so there's a good argument they shouldn't change anything on their side

@benmccann benmccann added the vite label Oct 21, 2022
@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2022

🦋 Changeset detected

Latest commit: 8c1257c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@Rich-Harris
Copy link
Member

Could we do something like req.url = req.originalUrl in the middleware? This change makes me nervous, it feels like a workaround rather than a fix

@benmccann
Copy link
Member Author

Yeah, that works too and is even easier. Done.

@Conduitry
Copy link
Member

Was there something else with vite preview that you wanted to address that isn't covered by this?

@benmccann
Copy link
Member Author

I don't think we'd have to do it in preview because I don't think Vite's base middleware will be invoked there. E.g. we're responsible for serving static assets in preview and that will remain the case even with Vite 4:

sirv(join(svelte_config.kit.outDir, 'output/client'), {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants