-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Clear and concise description of the problem
In vite's ProxyOptions, rewrite
is defined as a simple string => string
transformer. However, http-proxy-middleware (which is what I am assuming inspired these options) added the ability for its pathRewrite
function to be async
in 0.21.0.
In my application, I use this method to test when a local backend service is running (via tcp-port-used
, which is async) and automatically transform the path into a shape which is agreeable to the local service. (another piece of code which is implemented on top of HPM's router option performs the host rewrite).
Suggested solution
Since vite passes the entire URL to this function, I believe that both pieces (host + path rewrite) could be implemented on top of this one function if it were made async. Additionally, given that the two places this is called (1, 2) look like they are express middlewares, I see no obvious reason why these couldn't be easily made async.
Happy to open a quick PR for this if the feature is agreeable. It should be backwards compatible as the signature can be changed to rewrite: (string) => string | Promise<string>
which is an awaitable signature. This blocks me from upgrading my applications to vite as our full stack developers make heavy use of this automatic proxying functionality and I'm not keen to take it away from them (everything else we have otherwise implemented on top of HPM appears to be implementable directly on top of http-proxy other than this piece).
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.