http-proxy-middleware
http-proxy-middleware copied to clipboard
How to "next" (skip middleware) based on the response?
I have a setup such as:
app.use('/', proxy({
changeOrigin: true,
target: PRERENDERED_APP_URL
}));
app.use('/', proxy({
changeOrigin: true,
target: APP_URL
}));
If PRERENDERED_APP_URL
responds with an error (e.g. status 404), I want to delegate the request to the next route. I do not see "next" as an option in the onProxyRes
.
Do you mean you want to proxy to APP_URL
when proxying to PRERENDERED_APP_URL
fails (with 404)?
Yes
I'm gonna look into it tomorrow because I have quite the same need: I need to be able to use middlewares for processing the proxy's response, or having a default one that will send the response as it is.
@gogson Did you have a chance to look into this?
@gajus I'm afraid I can't do anything without modifying the http-proxy module itself. I keep you posted.
@gajus I managed to do my thing I made a document about my solution. I didn't have much time to do that so it's quick'n'dirty but it works for my case: how to take a JSON response from the proxy and modify it before answering the request using route middlewares.
I'm not sure it will help you but you can look at my solution it may give you ideas. Don't hesitate to mail me if you need some hints.
Do you have any idea? @chimurai
I just want to do sth after finish proxying, looking forward to your reply.
@chimurai some news here?
If you want I can work on it, this feature its very important for us to allow our mock server to have a fallback in case that the proxied server returns some 4XX or 5XX http codes