-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Accept async
middlewares
#17421
Comments
Yeah, sadly there's been no commits to |
Express 5 has added support for this:
|
I just tested and polka has support for it as well. If there's an unhandled error in an Perhaps we should switch to polka |
Ah, there's a PR to switch to polka. So this would be addressed by #17569 |
Description
Most Vite middlewares need to be
async
especially because many of Vite's own APIs that you would be calling likessrLoadModule
areasync
. However,middlewares.use
does not acceptasync
methods. This makes for a pretty awkward dance to handle promise rejections and worse means that many users will overlook error handling altogether resulting in server crashesAlso, it would make sense for Vite's
errorMiddleware
to be called in the.catch
when invoking the promise as the rejection handler, but that's impossible for users to do as it's not exported. However, this could be done internally in Vite.Suggested solution
Override
middlewares.use
to accept async implementations or add amiddlewares.useAsync
methodAlternative
errorMiddleware
or have every consumer wrap their implementation in atry
/catch
so that it can never throw and implement their own custom error handlingconnect
to another server implementation which has nativeasync
handling like koaAdditional context
No response
Validations
The text was updated successfully, but these errors were encountered: