question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to "next" (skip middleware) based on the response?

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
rafa-ascommented, Dec 15, 2018

@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

1reaction
gogsoncommented, Jul 11, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Any way to conditionally skip middleware with next() in express?
My goal is to skip unnecessary middleware if information is already cached from previous routes. So in above example, feature2 doesnt have to ......
Read more >
Using middleware - Express.js
To skip the rest of the middleware functions from a router middleware stack, call next('route') to pass control to the next route. NOTE:...
Read more >
How to skip a middleware in Express.js ? - GeeksforGeeks
Step 1: Initialize node project. npm init · Step 2: Install required modules npm install express.
Read more >
Skipping middleware in Express.js - Tutorialspoint
Skipping middleware in Express.js - You need to pass some parameters to skip the middleware in an Express application.
Read more >
Advanced Features: Middleware - Next.js
Middleware allows you to run code before a request is completed, then based on the incoming request, you can modify the response by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found