proxy.bypass should support async functions #18920
Labels
contribution welcome
enhancement
New feature or request
p2-nice-to-have
Not breaking anything but nice to have (priority)
Describe the bug
I'm migrating our angular projects from webpack to esbuild/vite, and ran into a problem with the vite proxy: Any non-synchronous calls in
proxy.bypass
result in errors, though they kinda work:Promise
from the bypass function, I get a compile or typing error:I can tell from the code that there's no explicit support for Promises in the bypass implementation, and there are no tests, but interestingly it kinda works...
BUT the async call does complete successfully, and the browser receives the correct async proxied result.
proxy.target
value (as the error message suggests), it is used instead and resolves, and when my async bypass function completes it fails because the response has already been written. So I get 2 errors, eg:Note that webpack's proxy bypass does support Promises.
Reproduction
https://github.com/johncrim/vite-bugs
Steps to reproduce
Open the browser, then visit the
/foo
URL. The page displays after 3 seconds, but the error listed above is shown in the terminal.I provided 2 forms of non-sychronous bypass functions, with and without Promises:
without Promises:
with Promises:
Both have the same problem. I think supporting
false | string | void | Promise<false | string | void>
for the bypass return type would be ideal, and at a minimum theviteProxyMiddleware
fn should exit after the bypass function is called if it doesn't return a string orfalse
. Ideally it would wait for the Promise to resolve, handle string and false the same way they're currently handled, and exit for any other Promise result.IMO
bypass
should actually bypass the proxy pipeline, except in the case of 404 or "new target URL returned".System Info
Used Package Manager
yarn
Logs
I don't believe the startup info is useful - this is a vanilla starter project with 2 custom config files. The error log is:
Error info inside
Validations
The text was updated successfully, but these errors were encountered: