node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Forward proxy with filtering

Open ranode opened this issue 11 years ago • 4 comments

Hello! I would like to create a forward proxy that can filter our requests to certain restricted domains, but forward all other requests to the corresponding url in the internet and send the response back to the client - something like a web filter. Is this possible with this module? Couldn't find an example on the examples folder to do this. Is there any detailed documentation?

ranode avatar Mar 07 '15 10:03 ranode

+1 I'm also confused about this, in my opinion, "node-http-proxy" is aiming at reverse proxy, but we are looking for a forward proxy module

valaxy avatar Apr 20 '15 09:04 valaxy

+1

chbdetta avatar Aug 10 '15 04:08 chbdetta

I feel the same... all examples in node-http-proxy refer to hard-wired target URLs giving an indication that it is targeted as a reverse proxy. I did not see a single example anywhere of its use as a forward proxy. And when I tried, had all kinds of problems.

n-samir avatar Dec 19 '15 04:12 n-samir

Hi, a little late to the party but I am currently achieving this with the following code:

var server = http.createServer(function(req, res) {
  if (!! isFiltered(req)) {
    // Respond with FILTERED page
    return renderFiltered(res);
  }

  return proxy.web(req, res, {
    target: req.url,
    ignorePath: true,
    xfwd: true
  });
});

function renderFiltered(res) {
  res.writeHead(403, { 'Content-Type': 'text/html' });
  res.write(filteredHtml);
  res.end();
}

Unfortunately I am seeing some strange issues where CDNs are sending me 404s for certain files yet the requests from the proxy are identical to those coming from the browser - it's very odd.

** UPDATE: ** I resolved the 404s, it appears some wierdness within the path config was causing a duplication of the path so domain.com/path was becoming domain.com/path/path adding the ignorePath config prevents this.

Illizian avatar Jun 28 '16 09:06 Illizian