Choosing rewrite over pathRewrite in Vite Proxy: What about dynamic target resolution?
0 reputation · 19 Jul 2020, 20:48 UTC
Context
Vite’s dev‑server proxy accepts an object mapping request paths to options. The documented rewrite function transforms the incoming URL before forwarding, whereas the legacy pathRewrite option is no longer supported. In addition, the official docs only illustrate a static string for the target property, leaving the possibility of a dynamic target function ambiguous.
Unresolved Decision
When a proxy entry needs to route requests to different back‑ends based on runtime data (e.g., request method, headers, or query parameters), can the target be a function that returns a URL per request? If so, how does Vite evaluate this function—once at startup or on each request—and how does it interact with the rewrite logic, especially regarding query parameters?
Specific Questions
- Can the
targetoption be defined as a function that returns a URL based on the incoming request? - When a dynamic target is used, is it evaluated for every request or only once during server initialization?
- Does the
rewritefunction preserve query parameters when stripping a prefix, and how does this behavior change when combined with a dynamic target?