Http-proxy-middleware: How to "next" (skip middleware) based on the response?

Created on 5 Jul 2017  路  8Comments  路  Source: chimurai/http-proxy-middleware

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.

Most helpful comment

@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

All 8 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jack-Works picture Jack-Works  路  8Comments

ghostd picture ghostd  路  7Comments

ubreddy picture ubreddy  路  5Comments

DylanPiercey picture DylanPiercey  路  6Comments

nikksan picture nikksan  路  3Comments