Simpler dev server proxy fallback #20538
ThibautMarechal
started this conversation in
Feedback
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
After migrating to Vite, I'm trying to replicate the same dev server proxy experience I had with my previous bundler.
Before Vite, I only needed to configure a single proxy rule, and any request that wasn’t handled by the bundler (e.g., static assets or SPA routes) was automatically forwarded to my backend. It was a simple and convenient fallback behavior.
With Vite, I find myself needing to explicitly list out all the path prefixes I want to proxy:
Using Vite proxy solution:
This approach is a bit cumbersome when many endpoints need to be forwarded, and it becomes even trickier when some of those endpoints include WebSocket connections (especially if they share a common prefix with HTTP endpoints).
To work around this, I created a plugin:
👉 https://gist.github.com/ThibautMarechal/d8e27b9d665e29903791f36f4ad05da7
It basically proxies everything Vite doesn’t serve directly to a backend target. That way, I don’t have to manage a long list of prefixes or handle mismatched behavior for websockets.
I’m wondering:
Am I missing something in the Vite documentation?
Is there a built-in way to achieve this kind of fallback proxying?
Would this be a reasonable feature to support in core or via an official plugin?
It seems like a valid and common use case to forward all unmatched requests to a backend during development.
Beta Was this translation helpful? Give feedback.
All reactions