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

Responding immediately to client without forwarding to proxy #464

Open
sscarduzio opened this issue Aug 2, 2020 · 1 comment
Open

Responding immediately to client without forwarding to proxy #464

sscarduzio opened this issue Aug 2, 2020 · 1 comment

Comments

@sscarduzio
Copy link

Sometimes, for a certan combination of method, path, header, I would like to bounce back the request BEFORE it's forwarded to the server.

I'm no sure where to create this response object, and how to return it so that the request never reaches the server.

I.e.

const proxy = require('express-http-proxy');
const app = require('express')();

const port = 5000

app.use(proxy('localhost:9200', {
  https: true,
  preserveHostHdr: true,
  parseReqBody: false,

  proxyErrorHandler: function (err, res, next) {
    if (err) console.log("ERROR!  ", err)
    next(err);
  },

  proxyReqPathResolver: function (req) {
    console.log("> "+req.method + " ",req.url)
    return req.url
  },
  
  proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
    // letting self signed ssl cert go through
    proxyReqOpts.rejectUnauthorized = false
    
    if(srcReq.path.indexOf("siem")>=0 && srcReq.method == 'PUT' && srcReq.statusCode == 400){
      console.log("responding immediately with a 200...")
       // return ???????? <--- I don't want this request to reach the server!
    }
    return proxyReqOpts;
  }

}));

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
@bilics
Copy link

bilics commented Feb 16, 2022

Is this possible? Also looking for this. Thanks!

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

2 participants