Skip to content
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

Question: How to cancel the request and return 401? #544

Open
cawoodmonads opened this issue Aug 8, 2024 · 0 comments
Open

Question: How to cancel the request and return 401? #544

cawoodmonads opened this issue Aug 8, 2024 · 0 comments

Comments

@cawoodmonads
Copy link

We want to check specific headers (say X-API-Key) and cancel the proxy request if they are incorrect.
We've tried putting the logic in a filter() function but return false does not cancel the request - it passes the request on to the next handler in express. Even if we .status(401).send().end() the request is still passed on to the next handler.

  filter: function(req, res) {
    if (req.header('x-api-key') !== 'secretkey') {
      res.status(401).send('Invalid X-API-Key!').end(); // This works for the client
      return false; // This causes an express error on the server
    }
    return true;
  },

How can we cancel/block the request from being proxied?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant