I am using the nodejitsu node-http-proxy module to implement a forward proxy. Here is my simplified code:
var httpApp = require('express')(),
http = require('http'),
httpProxy = require('http-proxy');
httpServer = http.createServer(httpApp);
proxy = httpProxy.createProxyServer({xfwd:true,ws:true});
httpApp.use(function(req,res) {
proxy.web(req,res, {xfwd: true, agent:http.globalAgent,
ws:true, target:req.originalUrl }, function(err){console.log(err);});
});
httpServer.listen(5000);
This very code worked for a couple of test sites but I knew that it was, like they say, too good to be true. When I tried some more URLs, it failed. I would get display as if I have poor band-width or an image or two would be missing from the display.
For simplicity, I have not included the code for ws, or https. In fact, I commented out that code to see if this works first. I have a reverse proxy working fine using this same proxy module. I noticed that all the examples in the documentation have hard-wired target URLs as used for reverse proxies.
Test cases: For example, cnbc.com works fine but when I click on a link, it returns a 404 not found.
I am testing on Firefox with proxy environment variables set in /etc/environment. That seems OK because it does go to the right proxy server on the right port. I try the same URLs on the same machine under chrome without the proxy option set and these URLs display just fine.
Question: WHat issues am I not addressing in my forward proxy code?