I am trying to use node-http-proxy to proxy my site to another site eg google.com
whenever I try some of the examples they give in the docs on github instead of my site showing the content of google.com it just redirects to google.com this is the code I am using
var proxy = require("http-proxy");
var options = {
router: {
"myserver.com" : "google.com"
}
}
var proxyServer = proxy.createServer(options);
proxyServer.listen(80);
I am doing this wrong and its just for reverse proxy? If it is what in the node-http-proxy allows me to do regular proxies?
Because google.com returns a 301 redirect, it’ll send the browser to a different location. In this case, you can just use the full url (www.google.com), and it will not send back the 301 redirect to http://www.google.com. The important thing is that, since google.com is sending back a 301 redirect, you have to use the redirected website to not redirect the client. For example, if you run
curl google.com, you’ll see a 301 redirect, where if you just runcurl www.google.comthe redirect is not present.